mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 03:11:59 +00:00
* GuiSymbols.{cpp,h}:
- consider non-default document encodings. - only refresh categories when needed (speedup) - add tooltips. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22859 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
46e6cacfe0
commit
92b41f3f98
@ -17,6 +17,7 @@
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "Encoding.h"
|
||||
|
||||
@ -143,6 +144,16 @@ UnicodeBlocks unicode_blocks[] = {
|
||||
|
||||
const int no_blocks = sizeof(unicode_blocks) / sizeof(UnicodeBlocks);
|
||||
|
||||
|
||||
QString getCodePoint(char_type c)
|
||||
{
|
||||
QString cp = QString::number(c, 16);
|
||||
while (cp.size() < 4)
|
||||
cp.prepend('0');
|
||||
cp.prepend("0x");
|
||||
return cp;
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
@ -167,7 +178,10 @@ void GuiSymbols::updateView()
|
||||
{
|
||||
chosenLE->clear();
|
||||
|
||||
string const & new_encoding = bufferview()->cursor().getEncoding()->name();
|
||||
string new_encoding = bufferview()->cursor().getEncoding()->name();
|
||||
if (buffer().params().inputenc != "auto" &&
|
||||
buffer().params().inputenc != "default")
|
||||
new_encoding = buffer().params().encoding().name();
|
||||
if (new_encoding == encoding_)
|
||||
// everything up to date
|
||||
return;
|
||||
@ -239,7 +253,7 @@ void GuiSymbols::on_symbolsLW_itemClicked(QListWidgetItem * item)
|
||||
void GuiSymbols::on_categoryCO_activated(QString const & text)
|
||||
{
|
||||
if (!categoryFilterCB->isChecked())
|
||||
updateSymbolList();
|
||||
updateSymbolList(false);
|
||||
if (used_blocks.find(text) != used_blocks.end())
|
||||
symbolsLW->scrollToItem(used_blocks[text],
|
||||
QAbstractItemView::PositionAtTop);
|
||||
@ -248,7 +262,7 @@ void GuiSymbols::on_categoryCO_activated(QString const & text)
|
||||
|
||||
void GuiSymbols::on_categoryFilterCB_toggled(bool on)
|
||||
{
|
||||
updateSymbolList();
|
||||
updateSymbolList(false);
|
||||
if (on) {
|
||||
QString const category = categoryCO->currentText();
|
||||
if (used_blocks.find(category) != used_blocks.end())
|
||||
@ -258,15 +272,17 @@ void GuiSymbols::on_categoryFilterCB_toggled(bool on)
|
||||
}
|
||||
|
||||
|
||||
void GuiSymbols::updateSymbolList()
|
||||
void GuiSymbols::updateSymbolList(bool update_combo)
|
||||
{
|
||||
QString category = categoryCO->currentText();
|
||||
bool const nocategory = category.isEmpty();
|
||||
char_type range_start = 0x0000;
|
||||
char_type range_end = 0x110000;
|
||||
symbolsLW->clear();
|
||||
if (update_combo) {
|
||||
used_blocks.clear();
|
||||
categoryCO->clear();
|
||||
}
|
||||
bool const show_all = categoryFilterCB->isChecked();
|
||||
|
||||
typedef set<char_type> SymbolsList;
|
||||
@ -294,22 +310,34 @@ void GuiSymbols::updateSymbolList()
|
||||
// we do not want control or space characters
|
||||
if (cat == QChar::Other_Control || cat == QChar::Separator_Space)
|
||||
continue;
|
||||
if (!update_combo && !show_all && (c <= range_start || c >= range_end))
|
||||
continue;
|
||||
QListWidgetItem * lwi = new QListWidgetItem(toqstr(c));
|
||||
if (show_all || c >= range_start && c <= range_end) {
|
||||
lwi->setTextAlignment(Qt::AlignCenter);
|
||||
lwi->setToolTip(
|
||||
qt_("Character: ") + toqstr(c) + "\n" +
|
||||
qt_("Code Point: ") + getCodePoint(c)
|
||||
);
|
||||
symbolsLW->addItem(lwi);
|
||||
}
|
||||
if (update_combo) {
|
||||
QString block = getBlock(c);
|
||||
if (category.isEmpty())
|
||||
category = block;
|
||||
if (used_blocks.find(block) == used_blocks.end())
|
||||
used_blocks[block] = lwi;
|
||||
}
|
||||
}
|
||||
|
||||
if (update_combo) {
|
||||
// update category combo
|
||||
for (UsedBlocks::iterator it = used_blocks.begin(); it != used_blocks.end(); ++it) {
|
||||
for (UsedBlocks::iterator it = used_blocks.begin();
|
||||
it != used_blocks.end(); ++it) {
|
||||
categoryCO->addItem(it->first);
|
||||
}
|
||||
}
|
||||
|
||||
int old = categoryCO->findText(category);
|
||||
if (old != -1)
|
||||
categoryCO->setCurrentIndex(old);
|
||||
|
@ -50,8 +50,11 @@ public Q_SLOTS:
|
||||
void on_chosenLE_textChanged(QString const &);
|
||||
|
||||
private:
|
||||
/// update the widgets (symbol browser, category combo)
|
||||
void updateSymbolList();
|
||||
/** update the widgets (symbol browser, category combo)
|
||||
* \p combo indicates if the combo box has to be refreshed
|
||||
* as well (which is rather expensive)
|
||||
**/
|
||||
void updateSymbolList(bool update_combo = true);
|
||||
/// get the unicode block associated with \p c
|
||||
QString const getBlock(char_type c) const;
|
||||
/// the encoding at cursor position
|
||||
|
Loading…
Reference in New Issue
Block a user