| 1 |
/* |
| 2 |
* libkysdk-qtwidgets's Library |
| 3 |
* |
| 4 |
* Copyright (C) 2023, KylinSoft Co., Ltd. |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 3 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* Authors: Zhen Sun <[email protected]> |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "ktoolbutton.h" |
| 24 |
#include "parmscontroller.h" |
| 25 |
#include "themeController.h" |
| 26 |
#include <QApplication> |
| 27 |
#include <QDebug> |
| 28 |
#include <QLinearGradient> |
| 29 |
#include <QPainter> |
| 30 |
#include <QPainterPath> |
| 31 |
#include <QStyleOption> |
| 32 |
#include <QStyleOptionToolButton> |
| 33 |
#include <QTimer> |
| 34 |
|
| 35 |
namespace kdk |
| 36 |
{ |
| 37 |
class KToolButtonPrivate : public QObject, public ThemeController |
| 38 |
{ |
| 39 |
Q_DECLARE_PUBLIC(KToolButton) |
| 40 |
Q_OBJECT |
| 41 |
|
| 42 |
public: |
| 43 |
KToolButtonPrivate(KToolButton *parent); |
| 44 |
~KToolButtonPrivate() |
| 45 |
{ |
| 46 |
} |
| 47 |
void changePalette(); |
| 48 |
void doLoadingFlash(); |
| 49 |
|
| 50 |
protected: |
| 51 |
void changeTheme(); |
| 52 |
|
| 53 |
private: |
| 54 |
KToolButton *q_ptr; |
| 55 |
KToolButtonType m_type; |
| 56 |
QLinearGradient m_pLinearGradient; |
| 57 |
bool m_isLoading; |
| 58 |
QTimer *m_pTimer; |
| 59 |
int m_flashState; |
| 60 |
bool m_hasArrow; |
| 61 |
QPixmap m_arrowPixmap; |
| 62 |
QColor m_pixColor; |
| 63 |
QSize m_pixmapSize; |
| 64 |
bool m_isIconColor; |
| 65 |
QColor m_iconColor; |
| 66 |
int m_bottomLeftRadius; |
| 67 |
int m_topLeftRadius; |
| 68 |
int m_topRightRadius; |
| 69 |
int m_bottomRightRadius; |
| 70 |
bool m_isBkgColorEnable; |
| 71 |
}; |
| 72 |
|
| 73 |
KToolButton::KToolButton(QWidget *parent) |
| 74 |
: QToolButton(parent) |
| 75 |
, d_ptr(new KToolButtonPrivate(this)) |
| 76 |
{ |
| 77 |
Q_D(KToolButton); |
| 78 |
d->m_pTimer = new QTimer(this); |
| 79 |
d->m_pTimer->setInterval(100); |
| 80 |
d->m_flashState = 0; |
| 81 |
d->m_isLoading = false; |
| 82 |
int radius = ThemeController::getRadiusFromDT("kradius-normal"); |
| 83 |
if (radius == -1) { |
| 84 |
d->m_bottomLeftRadius = 6; |
| 85 |
d->m_topLeftRadius = 6; |
| 86 |
d->m_topRightRadius = 6; |
| 87 |
d->m_bottomRightRadius = 6; |
| 88 |
} else { |
| 89 |
d->m_bottomLeftRadius = radius; |
| 90 |
d->m_topLeftRadius = radius; |
| 91 |
d->m_topRightRadius = radius; |
| 92 |
d->m_bottomRightRadius = radius; |
| 93 |
} |
| 94 |
d->m_isBkgColorEnable = false; |
| 95 |
setType(Flat); |
| 96 |
installEventFilter(this); |
| 97 |
QToolButton::setIcon(QIcon::fromTheme("open-menu-symbolic")); |
| 98 |
setFocusPolicy(Qt::FocusPolicy::TabFocus); |
| 99 |
d->changeTheme(); |
| 100 |
connect(d->m_gsetting,&QGSettings::changed,this,[=](QString key){ |
| 101 |
if(key == "styleName" || key == "iconThemeName" || key == "widgetThemeName") |
| 102 |
{ |
| 103 |
d->changeTheme(); |
| 104 |
} |
| 105 |
}); |
| 106 |
connect(d->m_pTimer, &QTimer::timeout, d, &KToolButtonPrivate::doLoadingFlash); |
| 107 |
connect(Parmscontroller::self(), &Parmscontroller::modeChanged, this, [=]() { |
| 108 |
updateGeometry(); |
| 109 |
}); |
| 110 |
connect(this, &KToolButton::toggled, this, [=](bool checked) { |
| 111 |
emit checkedChanged(checked); |
| 112 |
}); |
| 113 |
} |
| 114 |
|
| 115 |
KToolButtonType KToolButton::type() |
| 116 |
{ |
| 117 |
Q_D(KToolButton); |
| 118 |
return d->m_type; |
| 119 |
} |
| 120 |
|
| 121 |
void KToolButton::setType(KToolButtonType type) |
| 122 |
{ |
| 123 |
Q_D(KToolButton); |
| 124 |
d->m_type = type; |
| 125 |
d->changePalette(); |
| 126 |
} |
| 127 |
|
| 128 |
void KToolButton::setIcon(const QIcon &icon) |
| 129 |
{ |
| 130 |
Q_D(KToolButton); |
| 131 |
QToolButton::setIcon(icon); |
| 132 |
d->changeTheme(); |
| 133 |
} |
| 134 |
|
| 135 |
void KToolButton::setLoading(bool flag) |
| 136 |
{ |
| 137 |
Q_D(KToolButton); |
| 138 |
if (!isEnabled()) |
| 139 |
return; |
| 140 |
if (hasArrow()) |
| 141 |
return; |
| 142 |
d->m_isLoading = flag; |
| 143 |
if (flag) |
| 144 |
d->m_pTimer->start(); |
| 145 |
else |
| 146 |
d->m_pTimer->stop(); |
| 147 |
} |
| 148 |
|
| 149 |
bool KToolButton::isLoading() |
| 150 |
{ |
| 151 |
Q_D(KToolButton); |
| 152 |
return d->m_isLoading; |
| 153 |
} |
| 154 |
|
| 155 |
QIcon KToolButton::icon() |
| 156 |
{ |
| 157 |
return QToolButton::icon(); |
| 158 |
} |
| 159 |
|
| 160 |
void KToolButton::setArrow(bool flag) |
| 161 |
{ |
| 162 |
Q_D(KToolButton); |
| 163 |
if (!d->m_isLoading) |
| 164 |
d->m_hasArrow = flag; |
| 165 |
update(); |
| 166 |
} |
| 167 |
|
| 168 |
bool KToolButton::hasArrow() const |
| 169 |
{ |
| 170 |
Q_D(const KToolButton); |
| 171 |
return d->m_hasArrow; |
| 172 |
} |
| 173 |
|
| 174 |
void KToolButton::setIconColor(bool flag, QColor color) |
| 175 |
{ |
| 176 |
Q_D(KToolButton); |
| 177 |
d->m_isIconColor = flag; |
| 178 |
d->m_iconColor = color; |
| 179 |
update(); |
| 180 |
} |
| 181 |
|
| 182 |
void KToolButton::setBorderRadius(int bottomLeft, int topLeft, int topRight, int bottomRight) |
| 183 |
{ |
| 184 |
Q_D(KToolButton); |
| 185 |
d->m_bottomLeftRadius = bottomLeft; |
| 186 |
d->m_topLeftRadius = topLeft; |
| 187 |
d->m_topRightRadius = topRight; |
| 188 |
d->m_bottomRightRadius = bottomRight; |
| 189 |
} |
| 190 |
|
| 191 |
void KToolButton::setBackgroundColorEnabled(bool flag) |
| 192 |
{ |
| 193 |
Q_D(KToolButton); |
| 194 |
d->m_isBkgColorEnable = flag; |
| 195 |
} |
| 196 |
|
| 197 |
bool KToolButton::backgroundColorEnabled() |
| 198 |
{ |
| 199 |
Q_D(KToolButton); |
| 200 |
return d->m_isBkgColorEnable; |
| 201 |
} |
| 202 |
|
| 203 |
bool KToolButton::eventFilter(QObject *watched, QEvent *event) |
| 204 |
{ |
| 205 |
Q_D(KToolButton); |
| 206 |
QColor highlightColor = ThemeController::getCustomColorFromDT("highlight-active"); |
| 207 |
if (watched == this) { |
| 208 |
// 根据不同状态重绘icon颜色 |
| 209 |
if (highlightColor == Qt::transparent) { |
| 210 |
if (ThemeController::themeMode() == LightTheme) |
| 211 |
d->m_pixColor = ThemeController::getCustomColorFromDT("kgray-17"); |
| 212 |
else |
| 213 |
d->m_pixColor = ThemeController::getCustomColorFromDT("kwhite"); |
| 214 |
} else { |
| 215 |
switch (event->type()) { |
| 216 |
case QEvent::MouseButtonPress: |
| 217 |
if (isEnabled() && !d->m_isLoading) { |
| 218 |
if (ThemeController::themeMode() == LightTheme) |
| 219 |
d->m_pixColor = highlightColor.darker(120); |
| 220 |
else |
| 221 |
d->m_pixColor = highlightColor.lighter(120); |
| 222 |
} |
| 223 |
break; |
| 224 |
case QEvent::Enter: |
| 225 |
if (isEnabled() && !d->m_isLoading) { |
| 226 |
if (ThemeController::themeMode() == LightTheme) |
| 227 |
d->m_pixColor = highlightColor.darker(105); |
| 228 |
else |
| 229 |
d->m_pixColor = highlightColor.lighter(105); |
| 230 |
} |
| 231 |
break; |
| 232 |
case QEvent::FocusIn: |
| 233 |
if (isEnabled() && !d->m_isLoading) { |
| 234 |
if (ThemeController::themeMode() == LightTheme) |
| 235 |
d->m_pixColor = highlightColor.darker(120); |
| 236 |
else |
| 237 |
d->m_pixColor = highlightColor.lighter(120); |
| 238 |
} |
| 239 |
break; |
| 240 |
case QEvent::EnabledChange: { |
| 241 |
if (!isEnabled() && !d->m_isLoading) { |
| 242 |
if (d->m_isLoading) { |
| 243 |
d->m_isLoading = false; |
| 244 |
d->m_pTimer->stop(); |
| 245 |
} |
| 246 |
if (ThemeController::themeMode() == LightTheme) |
| 247 |
d->m_pixColor = ThemeController::getCustomColorFromDT("kgray-10"); |
| 248 |
else |
| 249 |
d->m_pixColor = ThemeController::getCustomColorFromDT("kgray-14"); |
| 250 |
} else if (isEnabled() && !d->m_isLoading) { |
| 251 |
if (ThemeController::themeMode() == LightTheme) |
| 252 |
d->m_pixColor = ThemeController::getCustomColorFromDT("kgray-17"); |
| 253 |
else |
| 254 |
d->m_pixColor = ThemeController::getCustomColorFromDT("kwhite"); |
| 255 |
} |
| 256 |
} break; |
| 257 |
case QEvent::MouseButtonRelease: |
| 258 |
if (isEnabled() && !d->m_isLoading) { |
| 259 |
if (ThemeController::themeMode() == LightTheme) |
| 260 |
d->m_pixColor = highlightColor.darker(105); |
| 261 |
else |
| 262 |
d->m_pixColor = highlightColor.lighter(105); |
| 263 |
} |
| 264 |
break; |
| 265 |
case QEvent::Leave: |
| 266 |
case QEvent::FocusOut: |
| 267 |
if (isEnabled() && !d->m_isLoading) { |
| 268 |
if (ThemeController::themeMode() == LightTheme) |
| 269 |
d->m_pixColor = ThemeController::getCustomColorFromDT("kgray-17"); |
| 270 |
else |
| 271 |
d->m_pixColor = ThemeController::getCustomColorFromDT("kwhite"); |
| 272 |
} |
| 273 |
break; |
| 274 |
default: |
| 275 |
break; |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
return QToolButton::eventFilter(watched, event); |
| 280 |
} |
| 281 |
|
| 282 |
QSize KToolButton::sizeHint() const |
| 283 |
{ |
| 284 |
Q_D(const KToolButton); |
| 285 |
|
| 286 |
QSize size(Parmscontroller::parm(Parmscontroller::Parm::PM_ToolButtonHeight), |
| 287 |
Parmscontroller::parm(Parmscontroller::Parm::PM_ToolButtonHeight)); |
| 288 |
if (d->m_hasArrow) |
| 289 |
size.setWidth(Parmscontroller::parm(Parmscontroller::Parm::PM_ToolButtonHeight) + 24); |
| 290 |
return size; |
| 291 |
} |
| 292 |
|
| 293 |
void KToolButton::paintEvent(QPaintEvent *event) |
| 294 |
{ |
| 295 |
Q_D(KToolButton); |
| 296 |
d->m_pLinearGradient.setStart(this->width() / 2, 0); |
| 297 |
d->m_pLinearGradient.setFinalStop(this->width() / 2, this->height()); |
| 298 |
QPainter painter(this); |
| 299 |
painter.setRenderHint(QPainter::SmoothPixmapTransform); |
| 300 |
|
| 301 |
// 绘制边框 |
| 302 |
QStyleOptionToolButton option; |
| 303 |
initStyleOption(&option); |
| 304 |
d->m_arrowPixmap = QIcon::fromTheme("ukui-down-symbolic").pixmap(option.iconSize); |
| 305 |
|
| 306 |
QPen pen; |
| 307 |
QColor color = ThemeController::getCustomColorFromDT("highlight-active"); |
| 308 |
pen.setColor(color); |
| 309 |
pen.setWidth(2); |
| 310 |
if (((QStyle::State_HasFocus & option.state) && isEnabled() && !isLoading() && (this->focusPolicy() != Qt::FocusPolicy::NoFocus)) && d->m_type != Frameless) |
| 311 |
painter.setPen(pen); |
| 312 |
else |
| 313 |
painter.setPen(Qt::NoPen); |
| 314 |
|
| 315 |
QColor startColor; |
| 316 |
QColor endColor; |
| 317 |
|
| 318 |
if(!isChecked()) |
| 319 |
{ |
| 320 |
if (!isEnabled()) |
| 321 |
{ |
| 322 |
if(type() != Flat) |
| 323 |
{ |
| 324 |
ThemeController::getGradientFromDT("kcomponent-disable", startColor, endColor); |
| 325 |
d->m_pLinearGradient.setColorAt(0, startColor); |
| 326 |
d->m_pLinearGradient.setColorAt(1, endColor); |
| 327 |
painter.setBrush(d->m_pLinearGradient); |
| 328 |
} |
| 329 |
else |
| 330 |
{ |
| 331 |
painter.setBrush(Qt::NoBrush); |
| 332 |
} |
| 333 |
} else if (QStyle::State_Sunken & option.state) { |
| 334 |
if(type() != Flat) |
| 335 |
{ |
| 336 |
ThemeController::getGradientFromDT("kcomponent-click", startColor, endColor); |
| 337 |
d->m_pLinearGradient.setColorAt(0, startColor); |
| 338 |
d->m_pLinearGradient.setColorAt(1, endColor); |
| 339 |
painter.setBrush(d->m_pLinearGradient); |
| 340 |
} |
| 341 |
else |
| 342 |
{ |
| 343 |
painter.setBrush(Qt::NoBrush); |
| 344 |
} |
| 345 |
} else if (QStyle::State_MouseOver & option.state) { |
| 346 |
if(type() != Flat) |
| 347 |
{ |
| 348 |
ThemeController::getGradientFromDT("kcomponent-hover", startColor, endColor); |
| 349 |
d->m_pLinearGradient.setColorAt(0, startColor); |
| 350 |
d->m_pLinearGradient.setColorAt(1, endColor); |
| 351 |
painter.setBrush(d->m_pLinearGradient); |
| 352 |
} |
| 353 |
else |
| 354 |
{ |
| 355 |
painter.setBrush(Qt::NoBrush); |
| 356 |
} |
| 357 |
} else { |
| 358 |
if(type() != Flat && type() != SemiFlat) |
| 359 |
{ |
| 360 |
ThemeController::getGradientFromDT("kcomponent-normal", startColor, endColor); |
| 361 |
d->m_pLinearGradient.setColorAt(0, startColor); |
| 362 |
d->m_pLinearGradient.setColorAt(1, endColor); |
| 363 |
painter.setBrush(d->m_pLinearGradient); |
| 364 |
} |
| 365 |
else |
| 366 |
{ |
| 367 |
painter.setBrush(Qt::NoBrush); |
| 368 |
} |
| 369 |
} |
| 370 |
} |
| 371 |
else |
| 372 |
{ |
| 373 |
if (!isEnabled()) |
| 374 |
{ |
| 375 |
ThemeController::getGradientFromDT("kbrand-disable", startColor, endColor); |
| 376 |
d->m_pLinearGradient.setColorAt(0, startColor); |
| 377 |
d->m_pLinearGradient.setColorAt(1, endColor); |
| 378 |
painter.setBrush(d->m_pLinearGradient); |
| 379 |
} else if (QStyle::State_Sunken & option.state) { |
| 380 |
ThemeController::getGradientFromDT("kbrand-click", startColor, endColor); |
| 381 |
d->m_pLinearGradient.setColorAt(0, startColor); |
| 382 |
d->m_pLinearGradient.setColorAt(1, endColor); |
| 383 |
painter.setBrush(d->m_pLinearGradient); |
| 384 |
} else if (QStyle::State_MouseOver & option.state) { |
| 385 |
ThemeController::getGradientFromDT("kbrand-hover", startColor, endColor); |
| 386 |
d->m_pLinearGradient.setColorAt(0, startColor); |
| 387 |
d->m_pLinearGradient.setColorAt(1, endColor); |
| 388 |
painter.setBrush(d->m_pLinearGradient); |
| 389 |
} else { |
| 390 |
ThemeController::getGradientFromDT("kbrand-normal", startColor, endColor); |
| 391 |
d->m_pLinearGradient.setColorAt(0, startColor); |
| 392 |
d->m_pLinearGradient.setColorAt(1, endColor); |
| 393 |
painter.setBrush(d->m_pLinearGradient); |
| 394 |
} |
| 395 |
} |
| 396 |
|
| 397 |
if (ThemeController::widgetTheme() == ClassicTheme) |
| 398 |
painter.drawRoundedRect(this->rect().adjusted(1, 1, -1, -1), 0, 0); |
| 399 |
else { |
| 400 |
QRect drawRect = this->rect().adjusted(1, 1, 0, 0); |
| 401 |
QPainterPath path; |
| 402 |
path.moveTo(drawRect.topLeft() + QPoint(0, d->m_topLeftRadius)); |
| 403 |
path.lineTo(drawRect.bottomLeft() - QPoint(0, d->m_bottomLeftRadius)); |
| 404 |
path.quadTo(drawRect.bottomLeft(), drawRect.bottomLeft() + QPoint(d->m_bottomLeftRadius, 0)); |
| 405 |
path.lineTo(drawRect.bottomRight() - QPoint(d->m_bottomRightRadius, 0)); |
| 406 |
path.quadTo(drawRect.bottomRight(), drawRect.bottomRight() - QPoint(0, d->m_bottomRightRadius)); |
| 407 |
path.lineTo(drawRect.topRight() + QPoint(0, d->m_topRightRadius)); |
| 408 |
path.quadTo(drawRect.topRight(), drawRect.topRight() - QPoint(d->m_topRightRadius, 0)); |
| 409 |
path.lineTo(drawRect.topLeft() + QPoint(d->m_topLeftRadius, 0)); |
| 410 |
path.quadTo(drawRect.topLeft(), drawRect.topLeft() + QPoint(0, d->m_topLeftRadius)); |
| 411 |
painter.drawPath(path); |
| 412 |
} |
| 413 |
|
| 414 |
// 绘制图标 |
| 415 |
QRect rect(0, 0, option.iconSize.width(), option.iconSize.height()); |
| 416 |
QPixmap pixmap = this->icon().pixmap(option.iconSize); |
| 417 |
|
| 418 |
if (!pixmap.isNull()) { |
| 419 |
if (ThemeController::isPixmapPureColor(pixmap)) { |
| 420 |
if(isChecked()) |
| 421 |
pixmap = ThemeController::drawColoredPixmap(pixmap, ThemeController::getCustomColorFromDT("kwhite")); |
| 422 |
else |
| 423 |
{ |
| 424 |
if (d->m_type == KToolButtonType::Flat || !isEnabled()) |
| 425 |
pixmap = ThemeController::drawColoredPixmap(pixmap, d->m_pixColor); |
| 426 |
else if (ThemeController::themeMode() == DarkTheme) |
| 427 |
pixmap = ThemeController::drawSymbolicColoredPixmap(pixmap); |
| 428 |
} |
| 429 |
} |
| 430 |
} |
| 431 |
if (d->m_isIconColor) { |
| 432 |
pixmap = ThemeController::drawColoredPixmap(pixmap, d->m_iconColor); |
| 433 |
} |
| 434 |
|
| 435 |
if (!hasArrow()) { |
| 436 |
rect.moveCenter(this->rect().center()); |
| 437 |
painter.drawPixmap(rect, pixmap); |
| 438 |
} else { |
| 439 |
QRect newRect = this->rect().adjusted(0, 0, -20, 0); |
| 440 |
rect.moveCenter(newRect.center()); |
| 441 |
|
| 442 |
if (sizePolicy().horizontalPolicy() == QSizePolicy::Expanding) |
| 443 |
this->style()->drawItemPixmap(&painter, this->rect(), Qt::AlignCenter, pixmap); |
| 444 |
else |
| 445 |
this->style()->drawItemPixmap(&painter, rect, Qt::AlignCenter, pixmap); |
| 446 |
QRect arrowRect(0, 0, option.iconSize.width(), option.iconSize.height()); |
| 447 |
arrowRect.moveLeft(this->rect().width() - option.iconSize.width() - 8); |
| 448 |
arrowRect.moveTop((this->height() - option.iconSize.height()) / 2); |
| 449 |
QPixmap arrowPixmap = d->m_arrowPixmap; |
| 450 |
if(isChecked()) |
| 451 |
arrowPixmap = ThemeController::drawSymbolicColoredPixmap(arrowPixmap); |
| 452 |
else if (d->m_type == KToolButtonType::Flat || !isEnabled()) |
| 453 |
arrowPixmap = ThemeController::drawColoredPixmap(arrowPixmap, d->m_pixColor); |
| 454 |
else if (ThemeController::themeMode() == DarkTheme) |
| 455 |
arrowPixmap = ThemeController::drawSymbolicColoredPixmap(arrowPixmap); |
| 456 |
|
| 457 |
if(property("isWindowButton").toBool() && !isActiveWindow()) |
| 458 |
{ |
| 459 |
if(ThemeController::themeMode() == LightTheme) |
| 460 |
{ |
| 461 |
QIcon icon = QIcon::fromTheme("ukui-down-symbolic"); |
| 462 |
QIcon::State state = QIcon::Off; |
| 463 |
if (option.state & QStyle::State_On) |
| 464 |
state = QIcon::On; |
| 465 |
arrowPixmap = icon.pixmap(option.iconSize, QIcon::Disabled, state); |
| 466 |
} |
| 467 |
else |
| 468 |
{ |
| 469 |
arrowPixmap = ThemeController::drawColoredPixmap(arrowPixmap,ThemeController::getCustomColorFromDT("kgray-14")); |
| 470 |
} |
| 471 |
} |
| 472 |
painter.drawPixmap(arrowRect, arrowPixmap); |
| 473 |
} |
| 474 |
} |
| 475 |
|
| 476 |
KToolButtonPrivate::KToolButtonPrivate(KToolButton *parent) |
| 477 |
: q_ptr(parent) |
| 478 |
, m_hasArrow(false) |
| 479 |
{ |
| 480 |
m_isIconColor = false; |
| 481 |
setParent(parent); |
| 482 |
} |
| 483 |
|
| 484 |
void KToolButtonPrivate::changePalette() |
| 485 |
{ |
| 486 |
Q_Q(KToolButton); |
| 487 |
|
| 488 |
} |
| 489 |
|
| 490 |
void KToolButtonPrivate::doLoadingFlash() |
| 491 |
{ |
| 492 |
Q_Q(KToolButton); |
| 493 |
if (m_flashState < 7) |
| 494 |
m_flashState++; |
| 495 |
else |
| 496 |
m_flashState = 0; |
| 497 |
if (ThemeController::themeMode() == LightTheme) { |
| 498 |
q->QToolButton::setIcon(QIcon::fromTheme(QString("ukui-loading-%1.symbolic").arg(m_flashState))); |
| 499 |
} else { |
| 500 |
q->QToolButton::setIcon(ThemeController::drawColoredPixmap(QIcon::fromTheme(QString("ukui-loading-%1.symbolic").arg(m_flashState)).pixmap(q->iconSize()), ThemeController::getCustomColorFromDT("kwhite"))); |
| 501 |
} |
| 502 |
} |
| 503 |
|
| 504 |
void KToolButtonPrivate::changeTheme() |
| 505 |
{ |
| 506 |
Q_Q(KToolButton); |
| 507 |
|
| 508 |
initThemeStyle(); |
| 509 |
changePalette(); |
| 510 |
if (ThemeController::themeMode() == LightTheme) { |
| 511 |
if (q->isEnabled()) |
| 512 |
m_pixColor = ThemeController::getCustomColorFromDT("kgray-17"); |
| 513 |
else |
| 514 |
m_pixColor = ThemeController::getCustomColorFromDT("kgray-10"); |
| 515 |
} else { |
| 516 |
if (q->isEnabled()) |
| 517 |
m_pixColor = ThemeController::getCustomColorFromDT("kwhite"); |
| 518 |
else |
| 519 |
m_pixColor = ThemeController::getCustomColorFromDT("kgray-14"); |
| 520 |
} |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
#include "ktoolbutton.moc" |
| 525 |
#include "moc_ktoolbutton.cpp" |