Fix UI of document color selection

The coloring of push buttons does not work with all themes, so use a
dedicated widget.

Also, accelerators have been used multiple times.
This commit is contained in:
Juergen Spitzmueller 2022-12-23 09:14:03 +01:00
parent 7015d7db07
commit d90484de0a
2 changed files with 361 additions and 271 deletions

View File

@ -86,9 +86,8 @@
#include <vector>
// a style sheet for buttons
// this is for example used for the background color setting button
static inline QString colorButtonStyleSheet(QColor const & bgColor)
// a style sheet for color frame widgets
static inline QString colorFrameStyleSheet(QColor const & bgColor)
{
if (bgColor.isValid()) {
QString rc = QLatin1String("background-color:");
@ -2260,10 +2259,10 @@ void GuiDocument::changeBackgroundColor()
rgb2qcolor(set_backgroundcolor), asQWidget());
if (!newColor.isValid())
return;
// set the button color and text
colorModule->backgroundPB->setStyleSheet(
colorButtonStyleSheet(newColor));
colorModule->backgroundPB->setText(qt_("&Change..."));
// set the color
colorModule->pageBackgroundCF->setVisible(true);
colorModule->pageBackgroundCF->setStyleSheet(
colorFrameStyleSheet(newColor));
// save color
set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
is_backgroundcolor = true;
@ -2273,10 +2272,9 @@ void GuiDocument::changeBackgroundColor()
void GuiDocument::deleteBackgroundColor()
{
// set the button color back to default by setting an empty StyleSheet
colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
// change button text
colorModule->backgroundPB->setText(qt_("&Default..."));
// set the color back to default by setting an empty StyleSheet
colorModule->pageBackgroundCF->setStyleSheet(QLatin1String(""));
colorModule->pageBackgroundCF->setVisible(false);
// save default color (white)
set_backgroundcolor = rgbFromHexName("#ffffff");
is_backgroundcolor = false;
@ -2290,10 +2288,10 @@ void GuiDocument::changeFontColor()
rgb2qcolor(set_fontcolor), asQWidget());
if (!newColor.isValid())
return;
// set the button color and text
colorModule->fontColorPB->setStyleSheet(
colorButtonStyleSheet(newColor));
colorModule->fontColorPB->setText(qt_("&Change..."));
// set the color
colorModule->mainTextCF->setVisible(true);
colorModule->mainTextCF->setStyleSheet(
colorFrameStyleSheet(newColor));
// save color
set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
is_fontcolor = true;
@ -2304,9 +2302,8 @@ void GuiDocument::changeFontColor()
void GuiDocument::deleteFontColor()
{
// set the button color back to default by setting an empty StyleSheet
colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
// change button text
colorModule->fontColorPB->setText(qt_("&Default..."));
colorModule->mainTextCF->setStyleSheet(QLatin1String(""));
colorModule->mainTextCF->setVisible(false);
// save default color (black)
set_fontcolor = rgbFromHexName("#000000");
is_fontcolor = false;
@ -2320,9 +2317,9 @@ void GuiDocument::changeNoteFontColor()
rgb2qcolor(set_notefontcolor), asQWidget());
if (!newColor.isValid())
return;
// set the button color
colorModule->noteFontColorPB->setStyleSheet(
colorButtonStyleSheet(newColor));
// set the color
colorModule->noteFontCF->setStyleSheet(
colorFrameStyleSheet(newColor));
// save color
set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
is_notefontcolor = true;
@ -2332,10 +2329,10 @@ void GuiDocument::changeNoteFontColor()
void GuiDocument::deleteNoteFontColor()
{
// set the button color back to pref
// set the color back to pref
theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
colorModule->noteFontColorPB->setStyleSheet(
colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
colorModule->noteFontCF->setStyleSheet(
colorFrameStyleSheet(rgb2qcolor(set_notefontcolor)));
is_notefontcolor = false;
change_adaptor();
}
@ -2347,9 +2344,9 @@ void GuiDocument::changeBoxBackgroundColor()
rgb2qcolor(set_boxbgcolor), asQWidget());
if (!newColor.isValid())
return;
// set the button color
colorModule->boxBackgroundPB->setStyleSheet(
colorButtonStyleSheet(newColor));
// set the color
colorModule->boxBackgroundCF->setStyleSheet(
colorFrameStyleSheet(newColor));
// save color
set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
is_boxbgcolor = true;
@ -2359,10 +2356,10 @@ void GuiDocument::changeBoxBackgroundColor()
void GuiDocument::deleteBoxBackgroundColor()
{
// set the button color back to pref
// set the color back to pref
theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
colorModule->boxBackgroundPB->setStyleSheet(
colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
colorModule->boxBackgroundCF->setStyleSheet(
colorFrameStyleSheet(rgb2qcolor(set_boxbgcolor)));
is_boxbgcolor = false;
change_adaptor();
}
@ -4099,26 +4096,30 @@ void GuiDocument::paramsToDialog()
//color
if (bp_.isfontcolor) {
colorModule->fontColorPB->setStyleSheet(
colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
}
colorModule->mainTextCF->setStyleSheet(
colorFrameStyleSheet(rgb2qcolor(bp_.fontcolor)));
colorModule->mainTextCF->setVisible(true);
} else
colorModule->mainTextCF->setVisible(false);
set_fontcolor = bp_.fontcolor;
is_fontcolor = bp_.isfontcolor;
colorModule->noteFontColorPB->setStyleSheet(
colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
colorModule->noteFontCF->setStyleSheet(
colorFrameStyleSheet(rgb2qcolor(bp_.notefontcolor)));
set_notefontcolor = bp_.notefontcolor;
is_notefontcolor = bp_.isnotefontcolor;
if (bp_.isbackgroundcolor) {
colorModule->backgroundPB->setStyleSheet(
colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
}
colorModule->pageBackgroundCF->setStyleSheet(
colorFrameStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
colorModule->pageBackgroundCF->setVisible(true);
} else
colorModule->pageBackgroundCF->setVisible(false);
set_backgroundcolor = bp_.backgroundcolor;
is_backgroundcolor = bp_.isbackgroundcolor;
colorModule->boxBackgroundPB->setStyleSheet(
colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
colorModule->boxBackgroundCF->setStyleSheet(
colorFrameStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
set_boxbgcolor = bp_.boxbgcolor;
is_boxbgcolor = bp_.isboxbgcolor;

View File

@ -1,152 +1,60 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ColorUi</class>
<widget class="QWidget" name="ColorUi" >
<property name="geometry" >
<widget class="QWidget" name="ColorUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>426</width>
<height>261</height>
<width>519</width>
<height>274</height>
</rect>
</property>
<property name="contextMenuPolicy" >
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string/>
</property>
<property name="toolTip" >
<property name="toolTip">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" >
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3" >
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="fontcolorGB" >
<property name="title" >
<widget class="QGroupBox" name="fontcolorGB">
<property name="title">
<string>Font Colors</string>
</property>
<property name="flat" >
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="fontColorLA" >
<property name="text" >
<string>Main text:</string>
</property>
<property name="buddy" >
<cstring>fontColorPB</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QPushButton" name="fontColorPB" >
<property name="maximumSize" >
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<widget class="QPushButton" name="fontColorPB">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip" >
<property name="toolTip">
<string>Click to change the color</string>
</property>
<property name="text" >
<string>Default...</string>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QToolButton" name="delFontColorTB" >
<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 row="0" column="3" >
<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>
<item row="1" column="0" >
<widget class="QLabel" name="noteFontColorLA" >
<property name="text" >
<string>Greyed-out notes:</string>
</property>
<property name="buddy" >
<cstring>fontColorPB</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QPushButton" name="noteFontColorPB" >
<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" >
<property name="text">
<string>&amp;Change...</string>
</property>
</widget>
</item>
<item row="1" column="2" >
<widget class="QToolButton" name="delNoteFontColorTB" >
<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 row="1" column="3" >
<item row="0" column="5">
<spacer>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
@ -154,137 +62,175 @@
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="noteFontColorLA">
<property name="text">
<string>Greyed-out notes:</string>
</property>
<property name="buddy">
<cstring>fontColorPB</cstring>
</property>
</widget>
</item>
<item row="1" column="5">
<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>
<item row="0" column="0">
<widget class="QLabel" name="fontColorLA">
<property name="text">
<string>Main text:</string>
</property>
<property name="buddy">
<cstring>fontColorPB</cstring>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="noteFontColorPB">
<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>C&amp;hange...</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QToolButton" name="delNoteFontColorTB">
<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 row="0" column="4">
<widget class="QToolButton" name="delFontColorTB">
<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>&amp;Reset</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
<property name="arrowType">
<enum>Qt::LeftArrow</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QFrame" name="mainTextCF">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QFrame" name="noteFontCF">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="backgroundGB" >
<property name="title" >
<widget class="QGroupBox" name="backgroundGB">
<property name="title">
<string>Background Colors</string>
</property>
<property name="flat" >
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" >
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout_2" >
<item row="0" column="0" >
<widget class="QLabel" name="backgroundColorLA" >
<property name="text" >
<string>Page:</string>
</property>
<property name="buddy" >
<cstring>backgroundPB</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QPushButton" name="backgroundPB" >
<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>Default...</string>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QToolButton" name="delBackgroundTB" >
<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 row="0" column="3" >
<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>
<item row="1" column="0" >
<widget class="QLabel" name="boxBackgroundColorLA" >
<property name="text" >
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="boxBackgroundColorLA">
<property name="text">
<string>Shaded boxes:</string>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>backgroundPB</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<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 row="1" column="2" >
<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 row="1" column="3" >
<item row="1" column="5">
<spacer>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
@ -292,6 +238,149 @@
</property>
</spacer>
</item>
<item row="1" column="4">
<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>Rese&amp;t</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
<property name="arrowType">
<enum>Qt::LeftArrow</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="backgroundColorLA">
<property name="text">
<string>Page:</string>
</property>
<property name="buddy">
<cstring>backgroundPB</cstring>
</property>
</widget>
</item>
<item row="0" column="5">
<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>
<item row="0" column="2">
<widget class="QPushButton" name="backgroundPB">
<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>Ch&amp;ange...</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QToolButton" name="delBackgroundTB">
<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>Re&amp;set</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
<property name="arrowType">
<enum>Qt::LeftArrow</enum>
</property>
</widget>
</item>
<item row="1" column="2">
<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>Chan&amp;ge...</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QFrame" name="pageBackgroundCF">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QFrame" name="boxBackgroundCF">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@ -299,10 +388,10 @@
</item>
<item>
<spacer>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" stdset="0">
<size>
<width>385</width>
<height>22</height>
@ -314,9 +403,9 @@
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11" />
<layoutdefault spacing="6" margin="11"/>
<includes>
<include location="local" >qt_i18n.h</include>
<include location="local">qt_i18n.h</include>
</includes>
<resources/>
<connections/>