Display manually set itemize symbols

Display manually set itemize symbols and their size in the work area.

Fix for bug #2277.

Also fixes a problem with document settings changed() not correctly emitted.
This commit is contained in:
Daniel Ramoeller 2021-11-13 10:24:53 +01:00 committed by Jean-Marc Lasgouttes
parent 9185fb8ccc
commit 122b452b20
6 changed files with 212 additions and 34 deletions

View File

@ -5157,31 +5157,8 @@ void Buffer::Impl::setLabel(ParIterator & it, UpdateType utype) const
switch(layout.labeltype) {
case LABEL_ITEMIZE: {
// At some point of time we should do something more
// clever here, like:
// par.params().labelString(
// bp.user_defined_bullet(par.itemdepth).getText());
// for now, use a simple hardcoded label
docstring itemlabel;
switch (par.itemdepth) {
case 0:
// • U+2022 BULLET
itemlabel = char_type(0x2022);
break;
case 1:
// U+2013 EN DASH
itemlabel = char_type(0x2013);
break;
case 2:
// U+2217 ASTERISK OPERATOR
itemlabel = char_type(0x2217);
break;
case 3:
// · U+00B7 MIDDLE DOT
itemlabel = char_type(0x00b7);
break;
}
par.params().labelString(itemlabel);
par.params().labelString(
bp.user_defined_bullet(par.itemdepth).getUnicode());
break;
}

View File

@ -54,7 +54,7 @@ Bullet::Bullet(int f, int c, int s)
Bullet::Bullet(docstring const & t)
: font(MIN), character(MIN), size(MIN), user_text(1), text(t)
: font(MIN), character(MIN), size(MIN), user_text(1), text(t), unicode(t)
{
testInvariant();
}
@ -98,6 +98,7 @@ void Bullet::setText(docstring const & t)
font = character = size = MIN;
user_text = 1;
text = t;
unicode = t;
testInvariant();
}
@ -120,6 +121,16 @@ int Bullet::getSize() const
}
FontSize Bullet::getFontSize() const
{
if (size >= 0)
return bulletFontSize(size);
else
return INHERIT_SIZE;
}
Bullet & Bullet::operator=(Bullet const & b)
{
b.testInvariant();
@ -128,6 +139,7 @@ Bullet & Bullet::operator=(Bullet const & b)
size = b.size;
user_text = b.user_text;
text = b.text;
unicode = b.unicode;
this->testInvariant();
return *this;
}
@ -141,6 +153,14 @@ docstring const & Bullet::getText() const
}
docstring const & Bullet::getUnicode() const
{
if (user_text == 0)
generateText();
return unicode;
}
bool operator==(const Bullet & b1, const Bullet & b2)
{
bool result = false;
@ -176,6 +196,7 @@ void Bullet::generateText() const
if ((font >= 0) && (character >= 0)) {
text = bulletEntry(font, character);
unicode = bulletUnicode(font, character);
if (size >= 0)
text = bulletSize(size) + text;
user_text = -1;
@ -345,6 +366,153 @@ docstring const Bullet::bulletEntry(int f, int c)
return from_ascii(BulletPanels[f][c]);
}
FontSize Bullet::bulletFontSize(int s)
{
// see comment at bulletSize
static FontSize BulletFontSize[SIZEMAX] = {
TINY_SIZE, SCRIPT_SIZE, FOOTNOTE_SIZE, SMALL_SIZE, NORMAL_SIZE,
LARGE_SIZE, LARGER_SIZE, LARGEST_SIZE, HUGE_SIZE, HUGER_SIZE
};
return BulletFontSize[s];
}
docstring const Bullet::bulletUnicode(int f, int c)
{
// see comment at bulletEntry
static int UnicodeBulletPanel0[CHARMAX] = {
/* standard */
0x02013, 0x22A2,
0x022A3, 0x0266D, 0x0266E,
0x0266F, 0x02217, 0x022C6,
0x02022, 0x02218, 0x022C5,
0x02020, 0x025B3,
0x025BD, 0x025C3,
0x025B9, 0x025C1, 0x025B7,
0x02295, 0x02296, 0x02297,
0x02298, 0x02299, 0x02660,
0x022C4, 0x025C7, /* \square */ 0x025FB,
0x02662, 0x02661,
0x02663, 0x02192, 0x02933,
0x021C0, 0x021C1,
0x021D2, 0x0227B
};
static int UnicodeBulletPanel1[CHARMAX] = {
/* amssymb */
0x021DB, 0x021A3,
0x021A0, 0x021DD,
0x021AC, 0x022B8,
0x022A0, 0x0229E, 0x0229F,
0x022A1, 0x022C7, 0x022AA,
0x022D6, 0x022D7, 0x02720,
0x02605, 0x02713, 0x022A9,
0x0223D, 0x0223C,
0x02B1D, 0x0229D,
0x0229B, 0x025CE,
0x022B2, 0x022B3,
0x025B3, 0x025BD,
0x025CA, 0x025FB, 0x025C0,
0x025B6, 0x025B4,
0x025BE, 0x029EB,
0x025FC
};
static int UnicodeBulletPanel2[CHARMAX] = {
/* psnfss1 */
0x025CF, 0x0274D,
0x025D7, 0x02295,
0x02297, 0x02022,
0x02727, 0x02726,
0x02756, 0x025C6,
0x025CA, 0x022C5,
0x02751, 0x02752,
0x0274F, 0x02750,
0x02206, 0x02207,
0x02758, 0x02759,
0x0275A, 0x025A0,
0x025B2, 0x025BC,
0x02217, 0x02723,
0x02722, 0x02732,
0x02731, 0x027A4,
0x02762, 0x02763,
0x02766, 0x02767,
0x027A2, 0x027A3
};
static int UnicodeBulletPanel3[CHARMAX] = {
/* psnfss2 */
0x0260E, 0x02706,
0x02702, 0x02704,
0x02707, 0x02708,
0x02709, 0x0261B,
0x0261E, 0x0270C,
0x0270D, 0x0270F,
0x02715, 0x02716,
0x0271B, 0x02719,
0x0271E, 0x0271D,
0x02717, 0x02718,
0x0271A, 0x0271C,
0x0271F, 0x02720,
0x02713, 0x02714,
0x02660, 0x02663,
0x02666, 0x02665,
0x02764, 0x02765,
0x02660, 0x02663,
0x02666, 0x02665
};
static int UnicodeBulletPanel4[CHARMAX] = {
/* psnfss3 */
0x02721, 0x0272C,
0x0272B, 0x02B51,
0x02730, 0x0272A,
0x0272E, 0x0272D,
0x0272F, 0x02735,
0x0273A, 0x02742,
0x02733, 0x02734,
0x02736, 0x02737,
0x02738, 0x02739,
0x0273C, 0x0273B,
0x0273D, 0x02749,
0x0273E, 0x02743,
0x02747, 0x02748,
0x0274A, 0x0274B,
0x02724, 0x02725,
0x02744, 0x02745,
0x02746, 0x02740,
0x0273F, 0x02741
};
static int UnicodeBulletPanel5[CHARMAX] = {
/* psnfss4 */
0x0279F, 0x027A0,
0x027A1, 0x027A8,
0x027A5, 0x027A6,
0x027AE, 0x027AD,
0x027AC, 0x027AB,
0x027AA, 0x027A9,
0x027AF, 0x027B1,
0x027BA, 0x027BB,
0x02711, 0x02712,
0x02799, 0x027B5,
0x027B3, 0x027B8,
0x027BC, 0x027BD,
0x0279B, 0x02192,
0x0279D, 0x0279E,
0x0279C, 0x02794,
0x02192, 0x021D2,
0x027BE, 0x027B2,
0x027A7, 0x02212
}; /* string const BulletPanels[][] */
static int * UnicodeBulletPanels[FONTMAX] = {
UnicodeBulletPanel0, UnicodeBulletPanel1,
UnicodeBulletPanel2, UnicodeBulletPanel3,
UnicodeBulletPanel4, UnicodeBulletPanel5
};
return docstring(1, char_type(UnicodeBulletPanels[f][c]));
}
void Bullet::testInvariant() const
{
#ifdef ENABLE_ASSERTIONS

View File

@ -13,6 +13,8 @@
#ifndef BULLET_H
#define BULLET_H
#include "FontEnums.h"
#include "support/docstring.h"
@ -42,8 +44,12 @@ public:
///
int getSize() const;
///
FontSize getFontSize() const;
///
docstring const & getText() const;
///
docstring const & getUnicode() const;
///
Bullet & operator=(Bullet const &);
///
friend bool operator==(Bullet const &, Bullet const &);
@ -75,7 +81,13 @@ private:
///
void generateText() const;
///
void generateUnicode() const;
///
static docstring const bulletSize(int);
///
static FontSize bulletFontSize(int);
///
static docstring const bulletUnicode(int, int);
///
int font;
@ -101,6 +113,7 @@ private:
and size settings.
*/
mutable docstring text;
mutable docstring unicode;
};

View File

@ -18,6 +18,7 @@
#include "Cursor.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "Bullet.h"
#include "Changes.h"
#include "Language.h"
#include "Layout.h"
@ -426,13 +427,26 @@ void RowPainter::paintLabel() const
if (str.empty())
return;
// different font for label separation and string
Layout const & layout = par_.layout();
FontInfo const font = labelFont(false);
FontMetrics const & fm = theFontMetrics(font);
int const x = row_.isRTL() ? row_.width() + fm.width(layout.labelsep)
: row_.left_margin - fm.width(layout.labelsep) - fm.width(str);
FontInfo lfont = font;
pi_.pain.text(int(xo_) + x, yo_, str, font);
// bullet?
if (layout.labeltype == LABEL_ITEMIZE) {
// get label font size from document properties
lfont.setSize(pi_.base.bv->buffer().params().user_defined_bullet(par_.itemdepth).getFontSize());
// realize to avoid assertion
lfont.realize(sane_font);
}
FontMetrics const & lfm = theFontMetrics(lfont);
int const x = row_.isRTL() ? row_.width() + fm.width(layout.labelsep)
: row_.left_margin - fm.width(layout.labelsep) - lfm.width(str);
pi_.pain.text(int(xo_) + x, yo_, str, lfont);
}

View File

@ -174,8 +174,8 @@ QPixmap getSelectedPixmap(QPixmap pixmap, QSize const icon_size)
void BulletsModule::setupPanel(QListWidget * lw, QString const & panelname,
int const font, string const folder)
{
connect(lw, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
this, SLOT(bulletSelected(QListWidgetItem *, QListWidgetItem*)));
connect(lw, SIGNAL(itemClicked(QListWidgetItem *)),
this, SLOT(bulletSelected(QListWidgetItem *)));
// add panelname to combox
bulletpaneCO->addItem(panelname);
@ -250,12 +250,18 @@ void BulletsModule::init()
}
void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
void BulletsModule::bulletSelected(QListWidgetItem * item)
{
int const level = levelLW->currentRow();
// no change
if (bullets_[level].getFont() == bulletpaneCO->currentIndex()
&& bullets_[level].getCharacter() == item->type())
return;
// unselect previous item
selectItem(current_font_, current_char_, false);
int const level = levelLW->currentRow();
bullets_[level].setCharacter(item->type());
bullets_[level].setFont(bulletpaneCO->currentIndex());
current_font_ = bulletpaneCO->currentIndex();

View File

@ -44,7 +44,7 @@ protected Q_SLOTS:
void on_bulletsizeCO_activated(int level);
void on_customCB_clicked(bool);
void on_customLE_textEdited(const QString &);
void bulletSelected(QListWidgetItem *, QListWidgetItem *);
void bulletSelected(QListWidgetItem *);
void showLevel(int);
private: