commit d5093f3354592c53c1d51256e9fafe4e9d1642f6
Author: Koji Yokota <[email protected]>
Date:   Sun Jun 7 11:24:02 2026 +0900

    Let index colors accept alpha values
---
 src/IndicesList.cpp                 | 16 ++++++++--------
 src/IndicesList.h                   |  8 ++++----
 src/frontends/Application.h         |  2 ++
 src/frontends/qt/GuiApplication.cpp | 19 +++++++++++++++++++
 src/frontends/qt/GuiBranches.cpp    |  4 ++--
 src/frontends/qt/GuiBranches.h      |  2 +-
 src/frontends/qt/GuiDocument.cpp    |  3 ++-
 src/frontends/qt/GuiIndices.cpp     | 12 ++++++++----
 src/frontends/qt/GuiIndices.h       |  2 ++
 9 files changed, 48 insertions(+), 20 deletions(-)

diff --git a/src/IndicesList.cpp b/src/IndicesList.cpp
index 66aa06bfc0..27a9c84ea5 100644
--- a/src/IndicesList.cpp
+++ b/src/IndicesList.cpp
@@ -36,9 +36,9 @@ Index::Index()
 {
        // no theApp() with command line export
        if (theApp())
-               theApp()->getRgbColor(Color_indexlabel, color_);
+               theApp()->getArgbColor(Color_indexlabel, color_);
        else
-               frontend::Application::getRgbColorUncached(Color_indexlabel, 
color_);
+               frontend::Application::getArgbColorUncached(Color_indexlabel, 
color_);
 }
 
 
@@ -66,13 +66,13 @@ void Index::setShortcut(docstring const & s)
 }
 
 
-RGBColor const & Index::color() const
+const ARGBColor &Index::color() const
 {
        return color_;
 }
 
 
-void Index::setColor(RGBColor const & c)
+void Index::setColor(ARGBColor const & c)
 {
        color_ = c;
 }
@@ -80,15 +80,15 @@ void Index::setColor(RGBColor const & c)
 
 void Index::setColor(string const & str)
 {
-       if (str.size() == 7 && str[0] == '#')
-               color_ = rgbFromHexName(str);
+       if ((str.size() == 9 || str.size() == 7) && str[0] == '#')
+               color_ = argbFromHexName(str);
        else {
                // no color set or invalid color -- use predefined color
                // no theApp() with command line export
                if (theApp())
-                       theApp()->getRgbColor(Color_indexlabel, color_);
+                       theApp()->getArgbColor(Color_indexlabel, color_);
                else
-                       
frontend::Application::getRgbColorUncached(Color_indexlabel, color_);
+                       
frontend::Application::getArgbColorUncached(Color_indexlabel, color_);
        }
 }
 
diff --git a/src/IndicesList.h b/src/IndicesList.h
index 7fab436d6b..57e94f6c51 100644
--- a/src/IndicesList.h
+++ b/src/IndicesList.h
@@ -51,11 +51,11 @@ public:
        ///
        void setShortcut(docstring const &);
        ///
-       RGBColor const & color() const;
+       ARGBColor const & color() const;
        ///
-       void setColor(RGBColor const &);
+       void setColor(ARGBColor const &);
        /**
-        * Set color from a string "#rrggbb".
+        * Set color from a string "#aarrggbb".
         * Use Color:background if the string is no valid color.
         * This ensures compatibility with LyX 1.4.0 that had the symbolic
         * color "none" that was displayed as Color:background.
@@ -68,7 +68,7 @@ private:
        ///
        docstring shortcut_;
        ///
-       RGBColor color_;
+       ARGBColor color_;
 };
 
 
diff --git a/src/frontends/Application.h b/src/frontends/Application.h
index 58daba8c81..3fa4fa4482 100644
--- a/src/frontends/Application.h
+++ b/src/frontends/Application.h
@@ -205,6 +205,8 @@ public:
        virtual bool getArgbColor(ColorCode col, ARGBColor & argbcol) = 0;
        /// Like getRgbColor(), but static and slower
        static bool getRgbColorUncached(ColorCode col, RGBColor & rgbcol);
+       /// Like getArgbColor(), but static and slower
+       static bool getArgbColorUncached(ColorCode col, ARGBColor & argbcol);
 
        /// \returns the draw strategy used by the application
        virtual DrawStrategy drawStrategy() const = 0;
diff --git a/src/frontends/qt/GuiApplication.cpp 
b/src/frontends/qt/GuiApplication.cpp
index 535404ccc0..cb68a0ba6d 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -3112,6 +3112,7 @@ bool GuiApplication::getRgbColor(ColorCode col, RGBColor 
& rgbcol)
        return true;
 }
 
+
 bool GuiApplication::getArgbColor(ColorCode col, ARGBColor &argbcol)
 {
        QColor const & qcol = d->color_cache_.get(col);
@@ -3146,6 +3147,24 @@ bool Application::getRgbColorUncached(ColorCode col, 
RGBColor & rgbcol)
 }
 
 
+bool Application::getArgbColorUncached(ColorCode col, ARGBColor & argbcol)
+{
+       QColor const qcol(lcolor.get32bitHexName(col).c_str());
+       if (!qcol.isValid()) {
+               argbcol.a = 0;
+               argbcol.r = 0;
+               argbcol.g = 0;
+               argbcol.b = 0;
+               return false;
+       }
+       argbcol.a = qcol.alpha();
+       argbcol.r = qcol.red();
+       argbcol.g = qcol.green();
+       argbcol.b = qcol.blue();
+       return true;
+}
+
+
 string const GuiApplication::hexName(ColorCode col)
 {
        return ltrim(fromqstr(d->color_cache_.get(col).name()), "#");
diff --git a/src/frontends/qt/GuiBranches.cpp b/src/frontends/qt/GuiBranches.cpp
index 5d6d88a687..e3ce31d9cd 100644
--- a/src/frontends/qt/GuiBranches.cpp
+++ b/src/frontends/qt/GuiBranches.cpp
@@ -77,7 +77,7 @@ GuiBranches::GuiBranches(QWidget * parent)
        newBranchLE->installEventFilter(this);
        newBranchLE->setValidator(new NoNewLineValidator(newBranchLE));
 
-       colorbg_ = ColorCache::setSwatchBackground(30, 10);
+       swatchbg_ = ColorCache::setSwatchBackground(30, 10);
 }
 
 
@@ -145,7 +145,7 @@ void GuiBranches::updateView()
                if (itemcolor.isValid()) {
                        QPixmap coloritem(30, 10);
                        coloritem.fill(itemcolor);
-                       coloritem = ColorCache::mergePixmaps(&coloritem, 
&colorbg_);
+                       coloritem = ColorCache::mergePixmaps(&coloritem, 
&swatchbg_);
                        newItem->setIcon(2, QIcon(coloritem));
                }
                newItem->setText(3, it->hasFileNameSuffix() ? qt_("Yes") : 
qt_("No"));
diff --git a/src/frontends/qt/GuiBranches.h b/src/frontends/qt/GuiBranches.h
index 684161d3b1..addc0336af 100644
--- a/src/frontends/qt/GuiBranches.h
+++ b/src/frontends/qt/GuiBranches.h
@@ -88,7 +88,7 @@ private:
        ///
        QStringList unknown_branches_;
        ///
-       QPixmap colorbg_;
+       QPixmap swatchbg_;
 };
 
 } // namespace frontend
diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index 65e5239b1f..8ae28b9a19 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -5354,7 +5354,7 @@ void GuiDocument::dispatchParams()
                        Branch const * branch = branchlist.find(current_branch);
                        string const bcolor = branch->color();
                        ARGBColor argbcol;
-                       if ((bcolor.size() == 7 || bcolor.size() ==9) && 
bcolor[0] == '#')
+                       if ((bcolor.size() == 9 || bcolor.size() == 7) && 
bcolor[0] == '#')
                                argbcol = lyx::argbFromHexName(bcolor);
                        else
                                
guiApp->getArgbColor(lcolor.getFromLyXName(bcolor), argbcol);
@@ -5378,6 +5378,7 @@ void GuiDocument::dispatchParams()
                        docstring const & current_index = it->shortcut();
                        Index const * index = 
indiceslist.findShortcut(current_index);
                        string const x11hexname = X11hexname(index->color());
+                       LYXERR0("param x11hexname = " << x11hexname);
                        // display the new color
                        docstring const str = current_index + ' ' + 
from_ascii(x11hexname);
                        dispatch(FuncRequest(LFUN_SET_COLOR, str));
diff --git a/src/frontends/qt/GuiIndices.cpp b/src/frontends/qt/GuiIndices.cpp
index bb4cd40721..c4650391bf 100644
--- a/src/frontends/qt/GuiIndices.cpp
+++ b/src/frontends/qt/GuiIndices.cpp
@@ -63,6 +63,8 @@ GuiIndices::GuiIndices(QWidget * parent)
 
        indexOptionsLE->setValidator(new NoNewLineValidator(indexOptionsLE));
        newIndexLE->setValidator(new NoNewLineValidator(newIndexLE));
+
+       swatchbg_ = ColorCache::setSwatchBackground(30, 10);
 }
 
 
@@ -136,10 +138,11 @@ void GuiIndices::updateView()
                QString const iname = toqstr(it->index());
                newItem->setText(0, iname);
 
-               QColor const itemcolor = rgb2qcolor(it->color());
+               QColor const itemcolor = argb2qcolor(it->color());
                if (itemcolor.isValid()) {
                        QPixmap coloritem(30, 10);
                        coloritem.fill(itemcolor);
+                       coloritem = ColorCache::mergePixmaps(&coloritem, 
&swatchbg_);
                        newItem->setIcon(1, QIcon(coloritem));
                }
                // restore selected index
@@ -288,13 +291,14 @@ void GuiIndices::toggleColor(QTreeWidgetItem * item)
        if (!index)
                return;
 
-       QColor const initial = rgb2qcolor(index->color());
-       QColor ncol = GuiDialog::getColor(initial, this);
+       QColor const initial = argb2qcolor(index->color());
+       QColor ncol = GuiDialog::getColor(initial, this, QString(),
+                                         QColorDialog::ShowAlphaChannel);
        if (!ncol.isValid())
                return;
 
        // add the color to the indiceslist
-       index->setColor(fromqstr(ncol.name()));
+       index->setColor(fromqstr(ncol.name(QColor::HexArgb)));
        newIndexLE->clear();
        updateView();
 }
diff --git a/src/frontends/qt/GuiIndices.h b/src/frontends/qt/GuiIndices.h
index efaec8354f..493cbc0f9e 100644
--- a/src/frontends/qt/GuiIndices.h
+++ b/src/frontends/qt/GuiIndices.h
@@ -64,6 +64,8 @@ private:
        bool readonly_;
        ///
        bool use_indices_;
+       ///
+       QPixmap swatchbg_;
 };
 
 } // namespace frontend
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to