summaryrefslogtreecommitdiffstats
path: root/kcharselect/kcharselectdia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kcharselect/kcharselectdia.cpp')
-rw-r--r--kcharselect/kcharselectdia.cpp177
1 files changed, 172 insertions, 5 deletions
diff --git a/kcharselect/kcharselectdia.cpp b/kcharselect/kcharselectdia.cpp
index d5232a8..33ed2c0 100644
--- a/kcharselect/kcharselectdia.cpp
+++ b/kcharselect/kcharselectdia.cpp
@@ -9,10 +9,15 @@
#include <stdlib.h>
+#include <tqcursor.h>
+#include <tqtimer.h>
+
#include <kdialog.h>
#include <tdeapplication.h>
#include <tdeaccel.h>
#include <tdeconfig.h>
+#include <tdelistview.h>
+#include <tdelistviewsearchline.h>
#include <tdelocale.h>
#include <tdeaction.h>
@@ -44,6 +49,62 @@ KCharSelectDia::KCharSelectDia(TQWidget *parent,const char *name,
TQ_SLOT(fontSelected(const TQString &)));
grid->addMultiCellWidget(charSelect, 0, 0, 0, 3);
+ // Add category browser dock widget
+ dCategories = new TQDockWindow(this, "categories");
+
+ TQVBox *cvbox = new TQVBox(dCategories);
+
+ categories = new TDEListView(cvbox, "dock_categories");
+ categories->addColumn(i18n("Codepoint"));
+ categories->addColumn(i18n("Name"));
+ categories->setRootIsDecorated(true);
+ categories->setResizeMode(TQListView::LastColumn);
+ categories->setAllColumnsShowFocus(true);
+ connect(categories, TQ_SIGNAL(currentChanged(TQListViewItem*)), this, TQ_SLOT(categorySelected(TQListViewItem*)));
+
+ TDEListViewSearchLineWidget *lvsw = new TDEListViewSearchLineWidget(categories, cvbox);
+
+ dCategories->setWidget(cvbox);
+ dCategories->setCaption(i18n("Categories"));
+ dCategories->setHorizontallyStretchable(true);
+ dCategories->setVerticallyStretchable(true);
+ dCategories->setResizeEnabled(true);
+ dCategories->setCloseMode(TQDockWindow::Always);
+
+ // BUG TDEMainWindow::saveMainWindowSettings() does not save TQDockWindow settings
+ TDEConfig *config = tdeApp->config();
+ config->setGroup("Docks");
+ TQt::Dock categoriesDock = (TQt::Dock)config->readNumEntry("Categories dock", TQt::DockLeft);
+ int categoriesIndex = config->readNumEntry("Categories index", 0);
+ bool categoriesNewline = config->readBoolEntry("Categories nl", false);
+ int categoriesOffset = config->readNumEntry("Categories offset", 0);
+ int categoriesSize = config->readNumEntry("Categories size", -1);
+ bool categoriesShown = config->readBoolEntry("Categories shown", true);
+
+ addDockWindow(dCategories, i18n("Categories"), categoriesDock);
+ moveDockWindow(dCategories, categoriesDock, categoriesNewline, categoriesIndex, categoriesOffset);
+ if (categoriesSize >= 0)
+ {
+ if (dCategories->orientation() == TQt::Horizontal)
+ {
+ dCategories->setFixedExtentHeight(categoriesSize);
+ }
+ else
+ {
+ dCategories->setFixedExtentWidth(categoriesSize);
+ }
+ }
+
+ TDEToggleAction *tCategories = new TDEToggleAction(i18n("Show categories dock"), 0,
+ this, TQ_SLOT(toggleCategoriesDock()), actionCollection(), "show_categories");
+
+ tCategories->setChecked(categoriesShown);
+ dCategories->setShown(categoriesShown);
+
+#include "categories.h"
+
+ TQTimer::singleShot(0, this, TQ_SLOT(populateCategories()));
+
// Build line editor
lined = new TQLineEdit(mainWidget);
lined->resize(lined->sizeHint());
@@ -78,7 +139,7 @@ KCharSelectDia::KCharSelectDia(TQWidget *parent,const char *name,
// Build menu
KStdAction::quit( this, TQ_SLOT(_exit()), actionCollection() );
-
+
new TDEAction(i18n("&To Clipboard"), "edit-copy",
TDEStdAccel::shortcut(TDEStdAccel::Copy), this, TQ_SLOT(toClip()), actionCollection(), "copy_clip" );
@@ -86,20 +147,20 @@ KCharSelectDia::KCharSelectDia(TQWidget *parent,const char *name,
TQ_SLOT(toClipUTF8()), actionCollection(), "copy_utf_8" );
(void)new TDEAction(i18n("To Clipboard &HTML"), 0, this,
TQ_SLOT(toClipHTML()), actionCollection(), "copy_html" );
-
+
new TDEAction(i18n("&From Clipboard"), "edit-paste",
TDEStdAccel::shortcut(TDEStdAccel::Paste), this, TQ_SLOT(fromClip()), actionCollection(), "from_clip" );
(void)new TDEAction(i18n("From Clipboard UTF-8"), 0, this,
TQ_SLOT(fromClipUTF8()), actionCollection(), "from_clip_utf8" );
-
+
i18n("From Clipboard HTML"); // Intended for future use
-
+
KStdAction::clear(this, TQ_SLOT(clear()), actionCollection(), "clear");
(void)new TDEAction(i18n("&Flip"), 0, this,
TQ_SLOT(flipText()), actionCollection(), "flip" );
(void)new TDEAction(i18n("&Alignment"), 0, this,
TQ_SLOT(toggleEntryDirection()), actionCollection(), "alignment" );
-
+
charSelect->setFocus();
entryDirection = direction;
@@ -114,7 +175,9 @@ KCharSelectDia::KCharSelectDia(TQWidget *parent,const char *name,
//==================================================================
void KCharSelectDia::charChanged(const TQChar &_chr)
{
+ if (vChr == _chr) return;
vChr = _chr;
+ updateCurrentCategory();
}
//==================================================================
@@ -269,6 +332,27 @@ void KCharSelectDia::_exit()
config->writeEntry("char",static_cast<int>(vChr.unicode()));
config->writeEntry("table",charSelect->tableNum());
config->writeEntry("entryDirection",entryDirection);
+
+ // BUG TDEMainWindow::saveMainWindowSettings() does not save TQDockWindow settings
+ TQt::Dock dock; int index, offset; bool nl;
+ if (getLocation(dCategories, dock, index, nl, offset))
+ {
+ config->setGroup("Docks");
+ config->writeEntry("Categories dock", dock);
+ config->writeEntry("Categories index", index);
+ config->writeEntry("Categories nl", nl);
+ config->writeEntry("Categories offset", offset);
+ config->writeEntry("Categories shown", dCategories->isShown());
+
+ if (dCategories->orientation() == TQt::Horizontal)
+ {
+ config->writeEntry("Categories size", dCategories->height());
+ }
+ else
+ {
+ config->writeEntry("Categories size", dCategories->width());
+ }
+ }
config->sync();
delete this;
@@ -287,3 +371,86 @@ void KCharSelectDia::help()
tdeApp->invokeHelp();
}
+//==================================================================
+void KCharSelectDia::populateCategories()
+{
+ categories->setCursor(TQCursor(TQt::BusyCursor));
+ categories->setEnabled(false);
+
+ TQMap<int, TQString>::iterator cit;
+ for (cit = mCategories.begin(); cit != mCategories.end(); ++cit)
+ {
+ TQString uc = TQString("%1").arg(cit.key(), 4, 16).replace(' ', '0');
+ TQStringList cdata = TQStringList::split("|", cit.data());
+ TQString category = cdata[0];
+ TQListViewItem *cItem = categories->findItem(category, 1);
+ if (!cItem)
+ {
+ cItem = new TQListViewItem(categories, uc, category);
+ }
+
+ if (cdata.count() > 1)
+ {
+ TQString subcategory = cdata[1];
+ new TQListViewItem(cItem, uc, subcategory);
+ }
+
+ tqApp->processEvents();
+ }
+
+ categories->setEnabled(true);
+ categories->setCursor(TQCursor(TQt::ArrowCursor));
+ updateCurrentCategory();
+}
+
+//==================================================================
+void KCharSelectDia::categorySelected(TQListViewItem *category)
+{
+ bool ok;
+ const int uc = category->text(0).toInt(&ok, 16);
+ if (!ok) return;
+
+ const int table = uc / 256;
+ charSelect->setTableNum(table);
+
+ const TQChar ch(uc);
+ charSelect->setChar(ch);
+}
+
+//==================================================================
+// Returns the category index corresponding to _chr
+int KCharSelectDia::categoryIndex(TQChar &_chr)
+{
+ TQMap<int, TQString>::iterator cit;
+ int uc = -1;
+ for (cit = mCategories.begin(); cit != mCategories.end(); ++cit)
+ {
+ if (cit.key() > vChr.unicode()) break;
+ uc = cit.key();
+ }
+ return uc;
+}
+
+//==================================================================
+// Updates category dock to reflect the category of the currently selected character
+void KCharSelectDia::updateCurrentCategory()
+{
+ int uc = categoryIndex(vChr);
+ if (uc < 0) return;
+
+ TQString codepoint = TQString("%1").arg(uc, 4, 16).replace(' ', '0');
+
+ TQListViewItem *lvi = categories->findItem(codepoint, 0);
+ if (!lvi) return;
+
+ categories->blockSignals(true);
+ categories->setCurrentItem(lvi);
+ categories->ensureItemVisible(lvi);
+ categories->blockSignals(false);
+}
+
+//==================================================================
+void KCharSelectDia::toggleCategoriesDock()
+{
+ dCategories->setShown(static_cast<const TDEToggleAction*>(TQObject::sender())->isChecked());
+} \ No newline at end of file