summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2017-08-30 13:34:25 +0200
committerSolomon Peachy <pizza@shaftnet.org>2020-11-04 13:14:42 +0000
commit235cdeca73d6403e15a172534d6662ff2e3986cf (patch)
tree164e36c65199648b100c1d9a3dbb8b65e1e71786
parentb200cd7e4a63eb887962778212130d72a6e8856a (diff)
downloadrockbox-235cdeca73d6403e15a172534d6662ff2e3986cf.tar.gz
rockbox-235cdeca73d6403e15a172534d6662ff2e3986cf.zip
qeditor: add better fallback mecanism for icons
Change-Id: Ib87406c95fc6c579f108b81246350d12de428ba4
-rw-r--r--utils/regtools/qeditor/utils.cpp69
-rw-r--r--utils/regtools/qeditor/utils.h5
2 files changed, 57 insertions, 17 deletions
diff --git a/utils/regtools/qeditor/utils.cpp b/utils/regtools/qeditor/utils.cpp
index ada52fd07a..458386b389 100644
--- a/utils/regtools/qeditor/utils.cpp
+++ b/utils/regtools/qeditor/utils.cpp
@@ -1991,7 +1991,7 @@ MessageWidget::MessageWidget(QWidget *parent)
1991 m_text->setWordWrap(true); 1991 m_text->setWordWrap(true);
1992 m_close = new QToolButton(this); 1992 m_close = new QToolButton(this);
1993 m_close->setText("close"); 1993 m_close->setText("close");
1994 m_close->setIcon(style()->standardIcon(QStyle::SP_DialogCloseButton)); 1994 m_close->setIcon(style()->standardIcon(QStyle::QStyle::SP_DialogCloseButton));
1995 m_close->setAutoRaise(true); 1995 m_close->setAutoRaise(true);
1996 1996
1997 QHBoxLayout *layout = new QHBoxLayout(this); 1997 QHBoxLayout *layout = new QHBoxLayout(this);
@@ -2074,26 +2074,47 @@ YIconManager *YIconManager::m_singleton = nullptr;
2074YIconManager::YIconManager() 2074YIconManager::YIconManager()
2075{ 2075{
2076 m_icon_name[ListAdd] = "list-add"; 2076 m_icon_name[ListAdd] = "list-add";
2077 m_icon_fallback[ListAdd] = QStyle::SP_CustomBase; /* drawn by RenderListAdd */
2077 m_icon_name[ListRemove] = "list-remove"; 2078 m_icon_name[ListRemove] = "list-remove";
2079 m_icon_fallback[ListRemove] = QStyle::SP_CustomBase; /* drawn by RenderListAdd */
2078 m_icon_name[DocumentNew] = "document-new"; 2080 m_icon_name[DocumentNew] = "document-new";
2081 m_icon_fallback[DocumentNew] = QStyle::SP_FileDialogNewFolder;
2079 m_icon_name[DocumentEdit] = "document-edit"; 2082 m_icon_name[DocumentEdit] = "document-edit";
2083 m_icon_fallback[DocumentEdit] = QStyle::SP_FileDialogContentsView;
2080 m_icon_name[DocumentOpen] = "document-open"; 2084 m_icon_name[DocumentOpen] = "document-open";
2085 m_icon_fallback[DocumentOpen] = QStyle::SP_DialogOpenButton;
2081 m_icon_name[DocumentSave] = "document-save"; 2086 m_icon_name[DocumentSave] = "document-save";
2087 m_icon_fallback[DocumentSave] = QStyle::SP_DialogSaveButton;
2082 m_icon_name[DocumentSaveAs] = "document-save-as"; 2088 m_icon_name[DocumentSaveAs] = "document-save-as";
2089 m_icon_fallback[DocumentSaveAs] = QStyle::SP_DialogSaveButton;
2083 m_icon_name[Preferences] = "preferences-system"; 2090 m_icon_name[Preferences] = "preferences-system";
2091 m_icon_fallback[Preferences] = QStyle::SP_FileDialogInfoView;
2084 m_icon_name[FolderNew] = "folder-new"; 2092 m_icon_name[FolderNew] = "folder-new";
2093 m_icon_fallback[FolderNew] = QStyle::SP_FileDialogNewFolder;
2085 m_icon_name[Computer] = "computer"; 2094 m_icon_name[Computer] = "computer";
2095 m_icon_fallback[Computer] = QStyle::SP_ComputerIcon;
2086 m_icon_name[Cpu] = "cpu"; 2096 m_icon_name[Cpu] = "cpu";
2097 m_icon_fallback[Cpu] = QStyle::SP_DriveHDIcon;
2087 m_icon_name[DialogError] = "dialog-error"; 2098 m_icon_name[DialogError] = "dialog-error";
2099 m_icon_fallback[DialogError] = QStyle::SP_MessageBoxCritical;
2088 m_icon_name[ViewRefresh] = "view-refresh"; 2100 m_icon_name[ViewRefresh] = "view-refresh";
2101 m_icon_fallback[ViewRefresh] = QStyle::SP_BrowserReload;
2089 m_icon_name[SytemRun] = "system-run"; 2102 m_icon_name[SytemRun] = "system-run";
2103 m_icon_fallback[SytemRun] = QStyle::SP_MediaPlay;
2090 m_icon_name[ApplicationExit] = "application-exit"; 2104 m_icon_name[ApplicationExit] = "application-exit";
2105 m_icon_fallback[ApplicationExit] = QStyle::SP_TitleBarCloseButton;
2091 m_icon_name[HelpAbout] = "help-about"; 2106 m_icon_name[HelpAbout] = "help-about";
2107 m_icon_fallback[HelpAbout] = QStyle::SP_MessageBoxInformation;
2092 m_icon_name[FormatTextBold] = "format-text-bold"; 2108 m_icon_name[FormatTextBold] = "format-text-bold";
2109 m_icon_fallback[FormatTextBold] = QStyle::SP_CustomBase; /* drawn by RenderLetter */
2093 m_icon_name[FormatTextItalic] = "format-text-italic"; 2110 m_icon_name[FormatTextItalic] = "format-text-italic";
2111 m_icon_fallback[FormatTextItalic] = QStyle::SP_CustomBase; /* drawn by RenderLetter */
2094 m_icon_name[FormatTextUnderline] = "format-text-underline"; 2112 m_icon_name[FormatTextUnderline] = "format-text-underline";
2113 m_icon_fallback[FormatTextUnderline] = QStyle::SP_CustomBase; /* drawn by RenderLetter */
2095 m_icon_name[TextGeneric] = "text-x-generic"; 2114 m_icon_name[TextGeneric] = "text-x-generic";
2115 m_icon_fallback[TextGeneric] = QStyle::SP_FileDialogDetailedView;
2096 m_icon_name[MultimediaPlayer] = "multimedia-player"; 2116 m_icon_name[MultimediaPlayer] = "multimedia-player";
2117 m_icon_fallback[MultimediaPlayer] = QStyle::SP_ComputerIcon;
2097} 2118}
2098 2119
2099YIconManager::~YIconManager() 2120YIconManager::~YIconManager()
@@ -2111,27 +2132,25 @@ QIcon YIconManager::GetIcon(IconType type)
2111{ 2132{
2112 if(type < 0 || type >= MaxIcon) 2133 if(type < 0 || type >= MaxIcon)
2113 return QIcon(); 2134 return QIcon();
2114 if(QIcon::hasThemeIcon(m_icon_name[type])) 2135 /* cache icons */
2115 return QIcon::fromTheme(m_icon_name[type]);
2116 /* render icon if needed */
2117 if(m_icon[type].isNull()) 2136 if(m_icon[type].isNull())
2118 Render(type); 2137 m_icon[type] = QIcon::fromTheme(m_icon_name[type], GetFallbackIcon(type));
2119 return m_icon[type]; 2138 return m_icon[type];
2120} 2139}
2121 2140
2122namespace 2141namespace
2123{ 2142{
2124 void RenderListAdd(QIcon& icon) 2143 QIcon RenderListAdd()
2125 { 2144 {
2126 QPixmap pix(64, 64); 2145 QPixmap pix(64, 64);
2127 pix.fill(Qt::transparent); 2146 pix.fill(Qt::transparent);
2128 QPainter paint(&pix); 2147 QPainter paint(&pix);
2129 paint.fillRect(30, 12, 4, 40, QColor(255, 0, 0)); 2148 paint.fillRect(30, 12, 4, 40, QColor(255, 0, 0));
2130 paint.fillRect(12, 30, 40, 4, QColor(255, 0, 0)); 2149 paint.fillRect(12, 30, 40, 4, QColor(255, 0, 0));
2131 icon = QIcon(pix); 2150 return QIcon(pix);
2132 } 2151 }
2133 2152
2134 void RenderListRemove(QIcon& icon) 2153 QIcon RenderListRemove()
2135 { 2154 {
2136 QPixmap pix(64, 64); 2155 QPixmap pix(64, 64);
2137 pix.fill(Qt::transparent); 2156 pix.fill(Qt::transparent);
@@ -2139,26 +2158,46 @@ namespace
2139 paint.setPen(QColor(255, 0, 0)); 2158 paint.setPen(QColor(255, 0, 0));
2140 paint.drawLine(12, 12, 52, 52); 2159 paint.drawLine(12, 12, 52, 52);
2141 paint.drawLine(12, 52, 52, 16); 2160 paint.drawLine(12, 52, 52, 16);
2142 icon = QIcon(pix); 2161 return QIcon(pix);
2143 } 2162 }
2144 2163
2145 void RenderUnknown(QIcon& icon) 2164 QIcon RenderUnknown()
2146 { 2165 {
2147 QPixmap pix(64, 64); 2166 QPixmap pix(64, 64);
2148 pix.fill(); 2167 pix.fill();
2149 QPainter paint(&pix); 2168 QPainter paint(&pix);
2150 paint.fillRect(0, 0, 64, 64, QColor(255, 0, 0)); 2169 paint.fillRect(0, 0, 64, 64, QColor(255, 0, 0));
2151 icon = QIcon(pix); 2170 return QIcon(pix);
2171 }
2172
2173 QIcon RenderText(const QString& str, bool bold, bool italic, bool underline)
2174 {
2175 QPixmap pix(64, 64);
2176 pix.fill();
2177 QPainter paint(&pix);
2178 QFont font = QApplication::font("QButton");
2179 font.setBold(bold);
2180 font.setItalic(italic);
2181 font.setUnderline(underline);
2182 font.setPixelSize(64);
2183 paint.setFont(font);
2184 paint.drawText(0, 0, 64, 64, Qt::AlignCenter, str);
2185 return QIcon(pix);
2152 } 2186 }
2153} 2187}
2154 2188
2155void YIconManager::Render(IconType type) 2189QIcon YIconManager::GetFallbackIcon(IconType type)
2156{ 2190{
2191 if(m_icon_fallback[type] != QStyle::SP_CustomBase)
2192 return QApplication::style()->standardIcon(m_icon_fallback[type]);
2157 switch(type) 2193 switch(type)
2158 { 2194 {
2159 case ListAdd: RenderListAdd(m_icon[type]); break; 2195 case ListAdd: return RenderListAdd(); break;
2160 case ListRemove: RenderListRemove(m_icon[type]); break; 2196 case ListRemove: return RenderListRemove(); break;
2161 default: RenderUnknown(m_icon[type]); break; 2197 case FormatTextBold: return RenderText("B", true, false, false);
2198 case FormatTextItalic: return RenderText("I", false, true, false);
2199 case FormatTextUnderline: return RenderText("U", false, false, true);
2200 default: return RenderUnknown(); break;
2162 } 2201 }
2163} 2202}
2164 2203
diff --git a/utils/regtools/qeditor/utils.h b/utils/regtools/qeditor/utils.h
index b9755cf3c3..655e3ae96f 100644
--- a/utils/regtools/qeditor/utils.h
+++ b/utils/regtools/qeditor/utils.h
@@ -732,11 +732,12 @@ public:
732 QIcon GetIcon(IconType it); 732 QIcon GetIcon(IconType it);
733 733
734protected: 734protected:
735 void Render(IconType type); 735 QIcon GetFallbackIcon(IconType it);
736 736
737 static YIconManager *m_singleton; // single instance 737 static YIconManager *m_singleton; // single instance
738 QIcon m_icon[MaxIcon]; /* list add icon */ 738 QIcon m_icon[MaxIcon]; /* cache icons */
739 QString m_icon_name[MaxIcon]; /* icon name from theme */ 739 QString m_icon_name[MaxIcon]; /* icon name from theme */
740 QStyle::StandardPixmap m_icon_fallback[MaxIcon]; /* icon from style */
740}; 741};
741 742
742class Misc 743class Misc