]> git.lyx.org Git - features.git/commitdiff
fileformat change: support to specify the background color of shaded boxes
authorUwe Stöhr <uwestoehr@web.de>
Thu, 8 Apr 2010 00:14:08 +0000 (00:14 +0000)
committerUwe Stöhr <uwestoehr@web.de>
Thu, 8 Apr 2010 00:14:08 +0000 (00:14 +0000)
- new buffer parameter \boxbgcolor

(I'm still working on the remaining issue #6626 as this affect not only this feature.)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34083 a592a061-630c-0410-9148-cb99ea01b6c8

development/FORMAT
lib/lyx2lyx/lyx_2_0.py
src/Buffer.cpp
src/BufferParams.cpp
src/BufferParams.h
src/LaTeXFeatures.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiDocument.h
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/ui/ColorUi.ui

index ee67835fb1657404fbf5173f3ab0845bddbe6354..49b2cbf7a613bcc63e0ae577f97ad26e1a5619f3 100644 (file)
@@ -7,6 +7,10 @@ The good example would be 2010-01-10 entry.
 
 -----------------------
 
+2010-04-08 Uwe Stöhr <uwestoehr@web.de>
+       * Format incremented to 385: support to change the background color
+         for shaded boxes: new buffer parameter \boxbgcolor
+
 2010-04-03 Uwe Stöhr <uwestoehr@web.de>
        * Format incremented to 384: support to specify a document-wide
          font color: new buffer parameter \fontcolor
index b446a5569c43c16b9f9788f37e91e924eaf907a1..d7f00c8e80ad4377b19990909797a80ee267714e 100644 (file)
@@ -1431,6 +1431,41 @@ def revert_fontcolor(document):
                            + '\\color{document_fontcolor}\n')
 
 
+def revert_shadedboxcolor(document):
+    " Reverts shaded box color to preamble code "
+    i = 0
+    colorcode = ""
+    while True:
+      i = find_token(document.header, "\\boxbgcolor", i)
+      if i == -1:
+          return
+      colorcode = get_value(document.header, '\\boxbgcolor', 0)
+      del document.header[i]
+      # the color code is in the form #rrggbb where every character denotes a hex number
+      # convert the string to an int
+      red = string.atoi(colorcode[1:3],16)
+      # we want the output "0.5" for the value "127" therefore increment here
+      if red != 0:
+          red = red + 1
+      redout = float(red) / 256
+      green = string.atoi(colorcode[3:5],16)
+      if green != 0:
+          green = green + 1
+      greenout = float(green) / 256
+      blue = string.atoi(colorcode[5:7],16)
+      if blue != 0:
+          blue = blue + 1
+      blueout = float(blue) / 256
+      # write the preamble
+      insert_to_preamble(0, document,
+                           '% Commands inserted by lyx2lyx to set the color\n'
+                           '% of boxes with shaded background\n'
+                           + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
+                           + '\\definecolor{shadecolor}{rgb}{'
+                           + str(redout) + ', ' + str(greenout)
+                           + ', ' + str(blueout) + '}\n')
+
+
 ##
 # Conversion hub
 #
@@ -1474,10 +1509,12 @@ convert = [[346, []],
            [381, []],
            [382, []],
            [383, []],
-           [384, []]
+           [384, []],
+           [385, []]
           ]
 
-revert =  [[383, [revert_fontcolor]],
+revert =  [[384, [revert_shadedboxcolor]],
+           [383, [revert_fontcolor]],
            [382, [revert_turkmen]],
            [381, [revert_notefontcolor]],
            [380, [revert_equalspacing_xymatrix]],
index 4a278219e7b4a415675dc09a189816984a2c0e63..cc7eae04f4ee355270dd1bad717687d853a812f2 100644 (file)
@@ -126,7 +126,7 @@ namespace {
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 384; // uwestoehr: support for document-wide font color
+int const LYX_FORMAT = 385; // uwestoehr: support to change the shaded box color
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
@@ -672,6 +672,7 @@ int Buffer::readHeader(Lexer & lex)
        params().fontcolor = lyx::rgbFromHexName("#000000");
        params().isfontcolor = false;
        params().notefontcolor = lyx::rgbFromHexName("#cccccc");
+       params().boxbgcolor = lyx::rgbFromHexName("#ff0000");
 
        for (int i = 0; i < 4; ++i) {
                params().user_defined_bullet(i) = ITEMIZE_DEFAULTS[i];
index 8f6d7fc5356f58adf045a4748b1b190841f7c6f8..dcb9fa6579a495aeae1a3656cc72f11ecaab4a31 100644 (file)
@@ -375,6 +375,7 @@ BufferParams::BufferParams()
        isfontcolor = false;
        // light gray is the default font color for greyed-out notes
        notefontcolor = lyx::rgbFromHexName("#cccccc");
+       boxbgcolor = lyx::rgbFromHexName("#ff0000");
        compressed = lyxrc.save_compressed;
        for (int iter = 0; iter < 4; ++iter) {
                user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
@@ -739,6 +740,13 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                // set the font color within LyX
                // FIXME: the color is correctly set but later overwritten by the default
                lcolor.setColor(Color_greyedouttext, color);
+       } else if (token == "\\boxbgcolor") {
+               lex.eatLine();
+               string color = lex.getString();
+               boxbgcolor = lyx::rgbFromHexName(color);
+               // set the font color within LyX
+               // FIXME: the color is correctly set but later overwritten by the default
+               lcolor.setColor(Color_shadedbg, color);
        } else if (token == "\\paperwidth") {
                lex >> paperwidth;
        } else if (token == "\\paperheight") {
@@ -935,6 +943,8 @@ void BufferParams::writeFile(ostream & os) const
                os << "\\fontcolor " << lyx::X11hexname(fontcolor) << '\n';
        if (notefontcolor != lyx::rgbFromHexName("#cccccc"))
                os << "\\notefontcolor " << lyx::X11hexname(notefontcolor) << '\n';
+       if (boxbgcolor != lyx::rgbFromHexName("#ff0000"))
+               os << "\\boxbgcolor " << lyx::X11hexname(boxbgcolor) << '\n';
 
        BranchList::const_iterator it = branchlist().begin();
        BranchList::const_iterator end = branchlist().end();
index 8ad2e064196e52f333e70e098085a7b7d1e09942..1e8174d12c33f02d9adc1cf48095b807e3f0d40c 100644 (file)
@@ -293,6 +293,8 @@ public:
        bool isfontcolor;
        ///
        RGBColor notefontcolor;
+       ///
+       RGBColor boxbgcolor;
        /// \param index should lie in the range 0 <= \c index <= 3.
        Bullet & temp_bullet(size_type index);
        Bullet const & temp_bullet(size_type index) const;
index f4a84566304d3dbcd56570f8a5c33ad5176b9686..615901f8936eea1430157d539bf70df20422d443 100644 (file)
@@ -604,6 +604,13 @@ string const LaTeXFeatures::getColorOptions() const
                // the lyxgreyedout environment (see lyxgreyedout_def)
        }
 
+       // color for shaded boxes
+       if (isRequired("framed") && mustProvide("color")) {
+               colors << "\\definecolor{shadecolor}{rgb}{";
+               colors << outputLaTeXColor(params_.boxbgcolor) << "}\n";
+               // this color is automatically used by the LaTeX-package "framed"
+       }
+
        return colors.str();
 }
 
@@ -693,21 +700,7 @@ string const LaTeXFeatures::getPackages() const
                                 << params_.graphicsDriver
                                 << "]{graphicx}\n";
        }
-       // shadecolor for shaded
-       if (isRequired("framed") && mustProvide("color")) {
-               RGBColor c = rgbFromHexName(lcolor.getX11Name(Color_shadedbg));
-               //255.0 to force conversion to double
-               //NOTE As Jürgen Spitzmüller pointed out, an alternative would be
-               //to use the xcolor package instead, and then we can do
-               // \define{shadcolor}{RGB}...
-               //and not do any conversion. We'd then need to require xcolor
-               //in InsetNote::validate().
-               int const stmSize = packages.precision(2);
-               packages << "\\definecolor{shadecolor}{rgb}{"
-                       << c.r / 255.0 << ',' << c.g / 255.0 << ',' << c.b / 255.0 << "}\n";
-               packages.precision(stmSize);
-       }
-
+       
        // lyxskak.sty --- newer chess support based on skak.sty
        if (mustProvide("chess"))
                packages << "\\usepackage[ps,mover]{lyxskak}\n";
index 9678dfc38d7efafceb46c0466597da9410406029..77923128dadddacec3ad511a1d7b96f6bb77b664 100644 (file)
@@ -182,6 +182,7 @@ bool is_backgroundcolor;
 RGBColor set_fontcolor;
 bool is_fontcolor;
 RGBColor set_notefontcolor;
+RGBColor set_boxbgcolor;
 
 namespace {
 // used when sorting the textclass list.
@@ -889,6 +890,10 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(changeBackgroundColor()));
        connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
                this, SLOT(deleteBackgroundColor()));
+       connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
+               this, SLOT(changeBoxBackgroundColor()));
+       connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
+               this, SLOT(deleteBoxBackgroundColor()));
 
 
        // numbering
@@ -1440,6 +1445,32 @@ void GuiDocument::deleteNoteFontColor()
 }
 
 
+void GuiDocument::changeBoxBackgroundColor()
+{
+       QColor const & newColor = QColorDialog::getColor(
+               rgb2qcolor(set_boxbgcolor), asQWidget());
+       if (!newColor.isValid())
+               return;
+       // set the button color
+       colorModule->boxBackgroundPB->setStyleSheet(
+               colorButtonStyleSheet(newColor));
+       // save color
+       set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
+       changed();
+}
+
+
+void GuiDocument::deleteBoxBackgroundColor()
+{
+       // set the button color back to red
+       colorModule->boxBackgroundPB->setStyleSheet(
+               colorButtonStyleSheet(QColor(Qt::red)));
+       // save red as the set color
+       set_boxbgcolor = rgbFromHexName("#ff0000");
+       changed();
+}
+
+
 void GuiDocument::xetexChanged(bool xetex)
 {
        updateFontlist();
@@ -2051,6 +2082,7 @@ void GuiDocument::applyView()
        bp_.fontcolor = set_fontcolor;
        bp_.isfontcolor = is_fontcolor;
        bp_.notefontcolor = set_notefontcolor;
+       bp_.boxbgcolor = set_boxbgcolor;
 
        // numbering
        if (bp_.documentClass().hasTocLevels()) {
@@ -2453,6 +2485,10 @@ void GuiDocument::paramsToDialog()
        set_backgroundcolor = bp_.backgroundcolor;
        is_backgroundcolor = bp_.isbackgroundcolor;
 
+       colorModule->boxBackgroundPB->setStyleSheet(
+               colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
+       set_boxbgcolor = bp_.boxbgcolor;
+
        // numbering
        int const min_toclevel = documentClass().min_toclevel();
        int const max_toclevel = documentClass().max_toclevel();
index 410b6b77bfca6dca19730829e4fc79b9f3276b70..d5b70c4afedac202fa261bd2ecd24592cd688481 100644 (file)
@@ -113,6 +113,8 @@ private Q_SLOTS:
        void deleteFontColor();
        void changeNoteFontColor();
        void deleteNoteFontColor();
+       void changeBoxBackgroundColor();
+       void deleteBoxBackgroundColor();
        void xetexChanged(bool);
        void branchesRename(docstring const &, docstring const &);
 private:
index 56b0beba3cdecd478d5495eccd03d1b9b7f84405..57047f419d4dafe07c7bb2809acbecbbd20fa2b9 100644 (file)
@@ -1006,7 +1006,8 @@ PrefColors::PrefColors(GuiPreferences * form)
                        || lc == Color_yellow
                        || lc == Color_inherit
                        || lc == Color_ignore
-                       || lc == Color_greyedouttext) continue;
+                       || lc == Color_greyedouttext
+                       || lc == Color_shadedbg) continue;
 
                lcolors_.push_back(lc);
        }
index 85c0a7b1e4d696a05799c68bbd0ac1005ef00c01..349af578d8a3222afd1b24d580b7067c563186a5 100644 (file)
@@ -6,7 +6,7 @@
     <x>0</x>
     <y>0</y>
     <width>406</width>
-    <height>275</height>
+    <height>322</height>
    </rect>
   </property>
   <property name="contextMenuPolicy">
   <property name="toolTip">
    <string/>
   </property>
-  <layout class="QGridLayout">
-   <property name="margin">
-    <number>11</number>
-   </property>
-   <property name="spacing">
-    <number>6</number>
-   </property>
+  <layout class="QGridLayout" name="gridLayout_2">
    <item row="0" column="0">
     <widget class="QGroupBox" name="fontcolorGB">
      <property name="title">
      <property name="flat">
       <bool>true</bool>
      </property>
-     <layout class="QGridLayout">
-      <property name="margin">
-       <number>11</number>
-      </property>
-      <property name="spacing">
-       <number>6</number>
-      </property>
+     <layout class="QGridLayout" name="gridLayout">
       <item row="0" column="0">
        <widget class="QLabel" name="backgroundColorLA">
         <property name="text">
-         <string>Background color:</string>
+         <string>Page:</string>
         </property>
         <property name="buddy">
          <cstring>backgroundPB</cstring>
         </item>
        </layout>
       </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="boxBackgroundColorLA">
+        <property name="text">
+         <string>Shaded boxes:</string>
+        </property>
+        <property name="buddy">
+         <cstring>backgroundPB</cstring>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <layout class="QHBoxLayout" name="_2">
+        <property name="spacing">
+         <number>6</number>
+        </property>
+        <property name="margin">
+         <number>11</number>
+        </property>
+        <item>
+         <widget class="QPushButton" name="boxBackgroundPB">
+          <property name="maximumSize">
+           <size>
+            <width>16777215</width>
+            <height>16777215</height>
+           </size>
+          </property>
+          <property name="toolTip">
+           <string>Click to change the color</string>
+          </property>
+          <property name="text">
+           <string>&amp;Change...</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QToolButton" name="delBoxBackgroundTB">
+          <property name="minimumSize">
+           <size>
+            <width>23</width>
+            <height>23</height>
+           </size>
+          </property>
+          <property name="toolTip">
+           <string>Revert the color to the default</string>
+          </property>
+          <property name="text">
+           <string>R&amp;eset</string>
+          </property>
+          <property name="toolButtonStyle">
+           <enum>Qt::ToolButtonTextOnly</enum>
+          </property>
+          <property name="arrowType">
+           <enum>Qt::LeftArrow</enum>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer>
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </item>
      </layout>
     </widget>
    </item>