GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — QtElementUI/QelButton/QelButton.cpp at develop · CPythoner/QtElementUI Expand file tree/ Copy pathQelButton.cppMore file actions 308 lines (255 loc) · 7.83 KB / Copy pathQelButton.cppFile metadata and controls308 lines (255 loc) · 7.83 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 #include "QelButton.h" #include <QColor> #include <QVariant> #include "../QelStyleHelper/QelStyleHelper.h" #include "../QelTheme/QelTheme.h" namespace qel { namespace { QelTheme::ButtonKind toButtonKind(QelButton::ButtonType type) { switch (type) { case QelButton::ButtonType::Primary: return QelTheme::ButtonKind::Primary; case QelButton::ButtonType::Success: return QelTheme::ButtonKind::Success; case QelButton::ButtonType::Warning: return QelTheme::ButtonKind::Warning; case QelButton::ButtonType::Danger: return QelTheme::ButtonKind::Danger; case QelButton::ButtonType::Info: return QelTheme::ButtonKind::Info; case QelButton::ButtonType::Default: default: return QelTheme::ButtonKind::Default; } } QColor semanticColor(QelButton::ButtonType type) { const QelTheme::ColorTokens &c = QelTheme::colors(); switch (type) { case QelButton::ButtonType::Primary: return QColor(c.primary); case QelButton::ButtonType::Success: return QColor(c.success); case QelButton::ButtonType::Warning: return QColor(c.warning); case QelButton::ButtonType::Danger: return QColor(c.danger); case QelButton::ButtonType::Info: return QColor(c.info); case QelButton::ButtonType::Default: default: return QColor(c.textRegular); } } QColor parseColorOrDefault(const QString &input, const QColor &fallback) { const QColor fromInput(input); if (fromInput.isValid()) { return fromInput; } return fallback; } void applyCustomColor(QelStyleHelper::StateStyleSet &styles, const QString &color) { const QelTheme::ColorTokens &c = QelTheme::colors(); const QColor base = parseColorOrDefault(color, QColor(c.primary)); const QColor hover = base.lighter(110); const QColor disabled = base.lighter(138); styles.normal.background = base.name(); styles.normal.border = base.name(); styles.normal.text = c.fillBlank; styles.hover.background = hover.name(); styles.hover.border = hover.name(); styles.hover.text = c.fillBlank; styles.active = styles.hover; styles.focus = styles.hover; styles.disabled.background = disabled.name(); styles.disabled.border = disabled.name(); styles.disabled.text = c.fillBlank; styles.loading = styles.disabled; } void applyTextLikeStyle(QelStyleHelper::StateStyleSet &styles, QelButton::ButtonType type, bool isLink, bool hasBackground) { const QelTheme::ColorTokens &c = QelTheme::colors(); const QColor semantic = semanticColor(type); const QString normalText = semantic.name(); const QString hoverText = semantic.lighter(115).name(); const QString disabledText = semantic.lighter(150).name(); styles.normal.background = hasBackground ? c.fillLight : "transparent"; styles.normal.border = "transparent"; styles.normal.text = normalText; styles.hover.background = hasBackground ? c.borderLight : c.primaryLight; styles.hover.border = "transparent"; styles.hover.text = hoverText; styles.active = styles.hover; styles.focus = styles.hover; styles.disabled.background = hasBackground ? c.fillLight : "transparent"; styles.disabled.border = "transparent"; styles.disabled.text = disabledText; styles.loading = styles.disabled; if (isLink) { styles.hover.background = "transparent"; styles.focus.background = "transparent"; } } } // namespace QelButton::QelButton(ButtonType type, ButtonSize size, bool isPlain, bool isRound, bool isCircle, bool isLoading, NativeButtonType nativeType, const QIcon &icon, const QString &text, QWidget *parent) : QPushButton(text, parent) , type_(type) , size_(size) , isPlain_(isPlain) , isRound_(isRound) , isCircle_(isCircle) , isLoading_(isLoading) , nativeType_(nativeType) { setIcon(icon); setProperty("qel-loading", isLoading_); setEnabled(!isLoading_); setCursor(Qt::PointingHandCursor); updateButtonStyle(); } void QelButton::setType(ButtonType type) { type_ = type; updateButtonStyle(); } void QelButton::setSize(ButtonSize size) { size_ = size; updateButtonStyle(); } void QelButton::setPlain(bool isPlain) { isPlain_ = isPlain; updateButtonStyle(); } void QelButton::setRound(bool isRound) { isRound_ = isRound; updateButtonStyle(); } void QelButton::setCircle(bool isCircle) { isCircle_ = isCircle; updateButtonStyle(); } void QelButton::setLoading(bool isLoading) { isLoading_ = isLoading; setEnabled(!isLoading_); setProperty("qel-loading", isLoading_); updateButtonStyle(); } void QelButton::setDisabled(bool isDisabled) { setEnabled(!isDisabled); updateButtonStyle(); } void QelButton::setIcon(const QIcon &icon) { QPushButton::setIcon(icon); } void QelButton::setAutofocus(bool autofocus) { setFocusPolicy(autofocus ? Qt::StrongFocus : Qt::NoFocus); } void QelButton::setNativeType(NativeButtonType nativeType) { nativeType_ = nativeType; if (nativeType == NativeButtonType::Submit) { setProperty("type", "submit"); } else if (nativeType == NativeButtonType::Reset) { setProperty("type", "reset"); } else { setProperty("type", "button"); } } void QelButton::setVisualType(VisualType visualType) { visualType_ = visualType; updateButtonStyle(); } void QelButton::setTextMode(bool isTextMode) { visualType_ = isTextMode ? VisualType::Text : VisualType::Filled; updateButtonStyle(); } void QelButton::setLinkMode(bool isLinkMode) { visualType_ = isLinkMode ? VisualType::Link : VisualType::Filled; updateButtonStyle(); } void QelButton::setBg(bool hasBackground) { hasBackground_ = hasBackground; updateButtonStyle(); } void QelButton::setColor(const QString &color) { customColor_ = color; updateButtonStyle(); } void QelButton::setDark(bool dark) { dark_ = dark; Q_UNUSED(dark_); updateButtonStyle(); } void QelButton::updateButtonStyle() { QString style; const QelTheme::ButtonKind kind = toButtonKind(type_); QelStyleHelper::StateStyleSet styles = QelStyleHelper::buttonStateStyles(kind, isPlain_); if (!customColor_.isEmpty()) { applyCustomColor(styles, customColor_); } if (visualType_ == VisualType::Text || visualType_ == VisualType::Link) { applyTextLikeStyle( styles, type_, visualType_ == VisualType::Link, hasBackground_); } style += QelStyleHelper::composeStateStyleSheet( "QPushButton", "QPushButton[qel-loading=\"true\"]", styles, true); QString sizeStyle; switch (size_) { case ButtonSize::Large: sizeStyle = "font-size: 16px; padding: 10px 20px;"; break; case ButtonSize::Default: sizeStyle = "font-size: 14px; padding: 8px 16px;"; break; case ButtonSize::Small: sizeStyle = "font-size: 13px; padding: 6px 12px;"; break; } QString roundStyle; if (isRound_) { roundStyle = QString("border-radius: %1px;").arg(height() / 2); } else { roundStyle = "border-radius: 4px;"; } if (visualType_ == VisualType::Link) { roundStyle = "border-radius: 0px;"; } if (isCircle_) { roundStyle = QString("border-radius: %1px;").arg(height() / 2); setFixedWidth(height()); } style += QString("QPushButton { %1 %2 }").arg(sizeStyle, roundStyle); if (visualType_ == VisualType::Link) { style += "QPushButton:hover { text-decoration: underline; }"; } setStyleSheet(style); } } // namespace qel |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |