commit 51027970a87ec0f8ffab4c8c31408e58af7e6310
Author: Koji Yokota <[email protected]>
Date:   Sat May 16 10:25:22 2026 +0900

    Introduction of RGBAColor struct
---
 src/Color.cpp                  | 31 ++++++++++++++++++++++---------
 src/ColorCode.h                | 20 ++++++++++++++++++++
 src/frontends/qt/GuiDialog.cpp |  4 ++--
 src/frontends/qt/GuiDialog.h   |  2 +-
 src/frontends/qt/GuiPrefs.cpp  |  2 +-
 5 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/src/Color.cpp b/src/Color.cpp
index 3977e998c6..2d77e7b7fb 100644
--- a/src/Color.cpp
+++ b/src/Color.cpp
@@ -67,8 +67,12 @@ string const X11hexname(RGBColor const & col)
 {
        ostringstream ostr;
 
-       ostr << '#' << setbase(16) << setfill('0')
-            << setw(2) << col.r
+       ostr << '#' << setbase(16) << setfill('0');
+
+       if (typeid(col) == typeid(RGBAColor))
+               ostr << setw(2) << ((RGBAColor const &)col).a;
+
+       ostr << setw(2) << col.r
             << setw(2) << col.g
             << setw(2) << col.b;
 
@@ -78,13 +82,22 @@ string const X11hexname(RGBColor const & col)
 
 RGBColor rgbFromHexName(string const & x11hexname)
 {
-       RGBColor c;
-       LASSERT(x11hexname.size() == 7 && x11hexname[0] == '#',
-               return c);
-       c.r = hexstrToInt(x11hexname.substr(1, 2));
-       c.g = hexstrToInt(x11hexname.substr(3, 2));
-       c.b = hexstrToInt(x11hexname.substr(5, 2));
-       return c;
+       LASSERT((x11hexname.size() == 7 || x11hexname.size() == 9)
+               && x11hexname[0] == '#', return RGBColor());
+       if (x11hexname.size() == 7) {
+               RGBColor c;
+               c.r = hexstrToInt(x11hexname.substr(1, 2));
+               c.g = hexstrToInt(x11hexname.substr(3, 2));
+               c.b = hexstrToInt(x11hexname.substr(5, 2));
+               return c;
+       } else {
+               RGBAColor c;
+               c.a = hexstrToInt(x11hexname.substr(1, 2));
+               c.r = hexstrToInt(x11hexname.substr(3, 2));
+               c.g = hexstrToInt(x11hexname.substr(5, 2));
+               c.b = hexstrToInt(x11hexname.substr(7, 2));
+               return c;
+       }
 }
 
 
diff --git a/src/ColorCode.h b/src/ColorCode.h
index 1cd7e61c1c..5c5b9cd039 100644
--- a/src/ColorCode.h
+++ b/src/ColorCode.h
@@ -272,6 +272,14 @@ struct RGBColor {
                : r(red), g(green), b(blue) {}
 };
 
+struct RGBAColor : public RGBColor {
+       unsigned int a;
+       RGBAColor() : RGBColor(), a(255) {}
+       RGBAColor(unsigned int red, unsigned int green, unsigned int blue,
+                 unsigned int alpha = 255)
+               : RGBColor(red, green, blue), a(alpha) {}
+};
+
 inline bool operator==(RGBColor const & c1, RGBColor const & c2)
 {
        return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
@@ -283,6 +291,18 @@ inline bool operator!=(RGBColor const & c1, RGBColor const 
& c2)
        return !(c1 == c2);
 }
 
+
+inline bool operator==(RGBAColor const & c1, RGBAColor const & c2)
+{
+       return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b && c1.a == c2.a);
+}
+
+
+inline bool operator!=(RGBAColor const & c1, RGBAColor const & c2)
+{
+       return !(c1 == c2);
+}
+
 } // namespace lyx
 
 #endif
diff --git a/src/frontends/qt/GuiDialog.cpp b/src/frontends/qt/GuiDialog.cpp
index 55b0acf8f9..af6ebc31d6 100644
--- a/src/frontends/qt/GuiDialog.cpp
+++ b/src/frontends/qt/GuiDialog.cpp
@@ -288,7 +288,7 @@ QString GuiDialog::browseRelToSub(
 
 QColor GuiDialog::getColor(const QColor &initial, QWidget *parent,
                            QString const & title,
-                              QColorDialog::ColorDialogOptions options)
+                           QColorDialog::ColorDialogOptions options)
 {
        const QColor color = QColorDialog::getColor(initial, parent, title, 
options);
        if (guiApp->platformName() == "cocoa") {
@@ -302,7 +302,7 @@ QColor GuiDialog::getColor(const QColor &initial, QWidget 
*parent,
 }
 
 QColor GuiDialog::getColor(const QColor &initial, QString const & title,
-                              QColorDialog::ColorDialogOptions options)
+                           QColorDialog::ColorDialogOptions options)
 {
        return getColor(initial, asQWidget(), title, options);
 }
diff --git a/src/frontends/qt/GuiDialog.h b/src/frontends/qt/GuiDialog.h
index 5f0fb68342..016fca19a9 100644
--- a/src/frontends/qt/GuiDialog.h
+++ b/src/frontends/qt/GuiDialog.h
@@ -185,7 +185,7 @@ public:
                               QColorDialog::ColorDialogOptions options
                               = QColorDialog::ColorDialogOptions());
        QColor getColor(const QColor &initial, QString const & title = 
QString(),
-                    QColorDialog::ColorDialogOptions options
+                       QColorDialog::ColorDialogOptions options
                        = QColorDialog::ColorDialogOptions());
 
 private:
diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp
index 4cbce38a0b..f75f914a3c 100644
--- a/src/frontends/qt/GuiPrefs.cpp
+++ b/src/frontends/qt/GuiPrefs.cpp
@@ -4729,7 +4729,7 @@ ColorSwatchDelegate::ColorSwatchDelegate(QObject *parent)
        QPolygon polygon;
        polygon << QPoint(pane_->swatch_width_, 0)
                << QPoint(0, pane_->swatch_height_)
-               << QPoint(pane_->swatch_width_, pane_->swatch_height_);
+               << QPoint(0, 0);
        painter.setPen(QColor(Qt::black));
        painter.setBrush(QColor(Qt::black));
        painter.drawPolygon(polygon);
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to